59

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'.

1 Answer 1

100

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 }})
Sign up to request clarification or add additional context in comments.

7 Comments

and what if use this with update_by_query api :) There should be no id parameter I guess.. Or ?
No that's different. update-by-query is an external plugin, not something that is supported by the elasticsearch-py library.
Is it possible use update_by_query in python with http request?
update by query for elasticsearch-py documentation is here elasticsearch-py.readthedocs.io/en/master/…
If you are using elasticsearch 7x - remember to remove doc_type
|

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.