gpt4 book ai didi

python - 使用python进行elasticsearch部分更新

转载 作者:太空狗 更新时间:2023-10-29 17:46:38 25 4
gpt4 key购买 nike

我有一个以下格式的 elasticsearch 文档。我需要部分更新“x”字段并在其中添加一个 python 字典。

{
"_index": "gdata34",
"_type": "gdat",
"_id": "328091-72341-118",
"_version": 1,
"_score": 1,
"_source": {
"d": {
"Thursday": {
"s": ""
},
"Email": {
"s": ""
},
"Country": {
"s": "US"
},

},
"x": {
"Geo": {
"s": "45.335428,-118.057133",
"g": [
-118.057133
,
45.335428
]
}
},
}
}

我尝试了以下代码来更新:

from elasticsearch import Elasticsearch, exceptions
import pprint


elasticsearch = Elasticsearch()
doc = elasticsearch.get(index='gdata34', doc_type='gdat', id='328091-72341-7')

elasticsearch.update(index='gdata34', doc_type='gdat', id='328091-72341-7',
body={"script":"ctx._source.x += y",
"params":{"y":"z"}
}
)
elasticsearch.indices.refresh(index='gdata34')
new_doc = elasticsearch.get(index='gdata34', doc_type='gdat', id='328091-72341-7')

我收到这个错误:

elasticsearch.exceptions.RequestError: TransportError(400, u'ElasticsearchIllegalArgumentException[failed to execute script]; nested: ScriptException[dynamic scripting for [groovy] disabled]; ')

使用 python 在 elasticsearch 中进行部分更新的正确方法是什么?

最佳答案

为了将来引用,以下部分更新方法有效。

elasticsearch.update(index='gdata34', doc_type='gdat', id='328091-72341-7',
body={
'doc': {'x': {'y':'z'}}
}
)

关于python - 使用python进行elasticsearch部分更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29469218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com