How to update a document using elasticsearch-py?

▼魔方 西西 提交于 2019-11-27 01:14:42

问题


Does anyone have an example for how to use update? It's documented here, but the documentation is unclear and doesn't included 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:


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 }})


来源:https://stackoverflow.com/questions/30598152/how-to-update-a-document-using-elasticsearch-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!