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.
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{}.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.