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'.
The script can update, delete, or skip modifying the document. The update API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API.
Elasticsearch allows us to do partial updates, but internally these are “get_then_update” operations, where the whole document is fetched, the changes are applied and then the document is indexed again. Even without disk hits one can imagine the potential performance implications if this is your main use case.
doc_type – The type of the document; deprecated and optional starting with 7.0. _source – True or false to return the _source field or not, or a list of fields to return.
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 }})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With