0

I can connect to and select the first record from an index. But I need to update the record with "newval" parameter. And update method is failing with error:

AttributeError: 'NoneType' object has no attribute 'copy'

Here is the code

import elasticsearch
from elasticsearch import helpers
es = elasticsearch.Elasticsearch('http://172.31.73.228:9200')

myquery={"query": {"match_all": {}}}
res = es.search(index="packetbeat-2017.06.12", body=myquery)

for i in range(2):
    print (res['hits']['hits'][i] )

The record returned that I need to update:

{'_index': 'packetbeat-2017.06.12', '_type': 'flow', '_id': 'AVyZmvuW4pXRFgxKGB7c', '_score': 1.0, '_source': {'@timestamp': '2017-06-12T00:01:30.000Z', 'beat': {'hostname': 'ip-172-31-73-228', 'name': 'ip-172-31-73-228', 'version': '5.4.1'}, 'dest': {'ip': '172.31.73.228', 'port': 9200, 'stats': {'net_bytes_total': 10015, 'net_packets_total': 46}}, 'final': True, 'flow_id': 'EAT/////AP//////CP8AAAFzfHHGrB9J5JLr8CM', 'last_time': '2017-06-12T00:00:30.732Z', 'source': {'ip': '115.124.113.198', 'port': 60306, 'stats': {'net_bytes_total': 141066, 'net_packets_total': 81}}, 'start_time': '2017-06-12T00:00:30.732Z', 'transport': 'tcp', 'type': 'flow'}}

my update method:

mybody={'doc': {'newval': 24}}

es.update('packetbeat-2017.06.12', 'flow', 'AVyZmvuW4pXRFgxKGB7c', body=mybody, params=None)

I am not able to add "newval" variable to the above record.

1
  • 1
    Why do you pass params=None? Commented Jun 26, 2017 at 11:58

1 Answer 1

1

The following snippet works correctly:

import elasticsearch
es = elasticsearch.Elasticsearch('http://localhost:9200')

res = es.search(index="packetbeat-2017.06.12", body={"query": {"match_all": {}}})

for single in res['hits']['hits']:
    print (single)

es.update('packetbeat-2017.06.12', 'flow', 'AVyZmvuW4pXRFgxKGB7c', body={'doc': {'newval': 24}})

Please consider avoiding doing this kind of request. Check the documentation about update by query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.