I've been trying to use update_by_query feature provided in python
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)
QUESTION : I am getting the following error below. Is even update_by_query supported by elastcisearch python module ??
>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**
However direct rest calls with elasticsearch are working fine.
POST /jagan4/_update_by_query
{
"script": {
"inline": "ctx._source.ID++",
"lang": "painless"
},
"query": {
"term": {
"username": "user100"
}
}
}