1

我一直在尝试使用 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)

问题:我收到以下错误。elastcisearch 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** 

然而,使用弹性搜索的直接休息调用工作正常。

POST /jagan4/_update_by_query  
{  
  "script": {  
    "inline": "ctx._source.ID++",  
    "lang": "painless"  
  },  
  "query": {  
    "term": {  
      "username": "user100"  
    }  
  }  
} 
4

0 回答 0