我将 Elasticsearch python 客户端用作 http://elasticsearch-py.readthedocs.org/ 我努力了,但仍然找不到带有 upsert 的更新 api。谁能给我一个 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
}
)
如果 body 没有 doc_as_upsert=true
,当 id 不存在时,代码会抛出异常。此外,请确保您的数据包含在 doc
中。
关于python - 如何使用python Elasticsearch客户端upsert api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226831/