how to use python Elasticsearch client upsert api

﹥>﹥吖頭↗ 提交于 2019-12-12 08:21:03

问题


I'm using Elasticsearch python client as http://elasticsearch-py.readthedocs.org/ I tried hard but still could not find the update api with upsert. Could anyone give me an example with ES python client upsert api please.


回答1:


The example code as following:

from elasticsearch import Elasticsearch
es = Elasticsearch("localhost:9200")
es.update(index='test',doc_type='test1',id='1',body={'doc':{'username':'Tom'},'doc_as_upsert':True})

if without doc_as_upsert=true it would throw exception when the id is not existing. Additionally, please make sure your data were wrapped in doc{}.




回答2:


Method index(*args, **kwargs) adds or updates a typed JSON document in a specific index, making it searchable.

As pointed out in Python Elasticsearch Client -> API Documentation.



来源:https://stackoverflow.com/questions/33226831/how-to-use-python-elasticsearch-client-upsert-api

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