如何使用python Elasticsearch客户端upsert api [英] how to use python Elasticsearch client upsert api

查看:1063
本文介绍了如何使用python Elasticsearch客户端upsert api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Elasticsearch python客户端作为 http://elasticsearch-py.readthedocs.org/
我努力尝试,但仍然找不到更新api与upsert。有人可以给我一个例子,ES python客户端upsert api请。

解决方案

示例代码如下:

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

如果没有 doc_as_upsert = true 当id不存在时,它将抛出异常。此外,请确保您的数据已被包装在doc {}中。


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{}.

这篇关于如何使用python Elasticsearch客户端upsert api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆