1

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"  
    }  
  }  
} 
  • Which version of elasticsearch-py do you have? You might be bumping into [this issue](https://github.com/elastic/elasticsearch-py/issues/417) – Val Jan 22 '17 at 08:08
  • @Vak: Thanks. Multiple versions were installed and I am using eclpise pydev. pip was showing 5.1 but dpkg was showing 1.6. After removing 1.6, it worked fine. – Jagannath Naidu Jan 22 '17 at 09:21

0 Answers0