我一直在尝试使用python
中提供的update_by_query功能from elasticsearch import Elasticsearch
import json
try:
es = Elasticsearch(['localhost','127.0.0.1'],port=9200,maxsize=25,)
print "Connected", es.info()
except Exception as ex:
print "Error:", ex
doc1 = {
"script": {
"inline": "ctx._source.ID++",
"lang": "painless"
},
"query": {
"term": {
"username": "user100"
}
}
}
# HERE I TRIED MULTIPLE WAYS BUT NONE OF THEM WORKED.
# res = es.update_by_query(index="jagan4", doc_type='1', body=doc1) # requies 4 args
# res = es.update_by_query(index="jagan4", doc_type='1', id='1' body=doc1) # no ID match, but why need id to for function.
res = es.update_by_query(index="jagan4", doc_type='1',q='username:"user100"', body=doc1)
问题:我在下面收到以下错误。即使是弹性系统python模块支持update_by_query ??
>Traceback (most recent call last):
File "/home/jagan/Desktop/DevStack/workspace/jj.python.first/src/el-test.py", line 42, in <module>
res = es.update_by_query(index="jagan4", doc_type='1',q='username:"user100"', body=doc1)
**AttributeError: 'Elasticsearch' object has no attribute 'update_by_query**
然而,使用elasticsearch的直接休息调用工作正常。
POST /jagan4/_update_by_query
{
"script": {
"inline": "ctx._source.ID++",
"lang": "painless"
},
"query": {
"term": {
"username": "user100"
}
}
}