如何使用elasticsearch-dsl软件包更新 elasticsearch 数据?那可能吗 ?
我找到了elasticsearch update api,但似乎有点困难。我要找的是
searchObj = Search(using=logserver, index=INDEX)
searchObj=searchObj.query("term",attribute=value).update(attribute=new_value)
response = searchObj.execute()
最佳答案
如果我没记错的话,elasticsearch_dsl
没有更新/批量更新的选项。
因此,您可以根据需要使用elasticsearch-py pckage。
示例
from elasticsearch import Elasticsearch
INDEX = 'myindex'
LOG_HOST = 'myhost:myport'
logserver = Elasticsearch(LOG_HOST)
script = "ctx._source.attribute = new_value"
update_body = {
"query": {
"bool": {
"filter": {
"term": {"attribute": "value"}
}
}
},
"script": {
"source": script,
"lang": "painless"
}
}
update_response = logserver.update_by_query(index=INDEX, body=update_body)
有关更多信息,请参见此official documentation。
关于python - 使用elasticserch dsl更新elasticsearch数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49045181/