How to update a document using elasticsearch-py?

PythonElasticsearchElasticsearch Py

Python Problem Overview


Does anyone have an example for how to use update? It's documented here, but the documentation is unclear and doesn't include a working example. I've tried the following:

coll = Elasticsearch()
coll.update(index='stories-test',doc_type='news',id=hit.meta.id,
                body={"stanford": 1, "parsed_sents": parsed })

and I get

elasticsearch.exceptions.RequestError: 
TransportError(400, u'ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]')

I would like to update using a partial doc, but the update method doesn't take any argument named 'doc' or 'document'.

Python Solutions


Solution 1 - Python

You're almost there, you just need to enclose your body inside a "doc" field. The correct way of doing a partial update with elasticsearch-py goes like this:

coll = Elasticsearch()
coll.update(index='stories-test',doc_type='news',id=hit.meta.id,
                body={"doc": {"stanford": 1, "parsed_sents": parsed }})

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan HookView Question on Stackoverflow
Solution 1 - PythonValView Answer on Stackoverflow