Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from elasticsearch import Elasticsearch
  2. import json
  3.  
  4. try:
  5. es = Elasticsearch(['localhost','127.0.0.1'],port=9200,maxsize=25,)
  6. print "Connected", es.info()
  7. except Exception as ex:
  8. print "Error:", ex
  9.  
  10. doc1 = {
  11. "script": {
  12. "inline": "ctx._source.ID++",
  13. "lang": "painless"
  14. },
  15. "query": {
  16. "term": {
  17. "username": "user100"
  18. }
  19. }
  20. }
  21.  
  22. # HERE I TRIED MULTIPLE WAYS BUT NONE OF THEM WORKED.
  23. # res = es.update_by_query(index="jagan4", doc_type='1', body=doc1) # requies 4 args
  24. # res = es.update_by_query(index="jagan4", doc_type='1', id='1' body=doc1) # no ID match, but why need id to for function.
  25. res = es.update_by_query(index="jagan4", doc_type='1',q='username:"user100"', body=doc1)
  26.  
  27. >Traceback (most recent call last):
  28. File "/home/jagan/Desktop/DevStack/workspace/jj.python.first/src/el-test.py", line 42, in <module>
  29. res = es.update_by_query(index="jagan4", doc_type='1',q='username:"user100"', body=doc1)
  30. **AttributeError: 'Elasticsearch' object has no attribute 'update_by_query**
  31.  
  32. POST /jagan4/_update_by_query
  33. {
  34. "script": {
  35. "inline": "ctx._source.ID++",
  36. "lang": "painless"
  37. },
  38. "query": {
  39. "term": {
  40. "username": "user100"
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement