I try to update a document in elasticsearch-py and I tried to work according to the following question:
How to update a document using elasticsearch-py?
However, I ran into some troubles and differences between elastisearch.create and elasticsearch.update and I do not find a way to solve this.
I have python objects, which I serialize using json.dumps:
json_create = json.dumps(document, cls=Encoder)
and I obtain a valid JSON document.
I then create the nodes with
res = es.index(my_index_id, 'my_data_type', json_create, my_identifier)
and everything works fine.
When I try to update a document, I do it similarly and create update_container objects to get the "doc"-object and node-strucutre right (as explaned in the above mentioned question):
update_json = json.dumps(update_container, cls=HiddenEncoder)
Again, if I print the result, I get a valid JSON document with something like
{"doc": {"data": {...}}
I then try to send the updates:
res = es.update(index=my_index_id, doc_type='my_doc_type', id=my_identifier, body=update_json)
However, when I execute this code, I get the following error:
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'failed to parse [data]')
If I use only the update part (without the container)
res = es.update(index=my_index_id, doc_type='my_doc_type', id=my_identifier, body={"doc": {"data": only_update_part}})
it works, but the data are not stored with all it subnodes, but are rather saved as one string with escaped quotation marks.
It seems to me, that in the create function, the data are send directly while in the update part, all quotation marks are escaped. Why do the two funtions handle the body differently? And how can I update the data-node with a complete object?
Thanks in advance!