How to update a document using elasticsearch-py?
48,996
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 }})
Author by
Dan Hook
Updated on July 09, 2022Comments
-
Dan Hook almost 2 years
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'.
-
Admin over 8 yearsand what if use this with update_by_query api :) There should be no id parameter I guess.. Or ?
-
Val over 8 yearsNo that's different. update-by-query is an external plugin, not something that is supported by the elasticsearch-py library.
-
Admin over 8 yearsIs it possible use update_by_query in python with http request?
-
David Kong over 4 yearsupdate by query for elasticsearch-py documentation is here elasticsearch-py.readthedocs.io/en/master/…
-
user8291021 about 4 yearsIf you are using elasticsearch 7x - remember to remove doc_type