python - 如何使用python Elasticsearch客户端upsert api

标签 python elasticsearch upsert

我将 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/

相关文章:

elasticsearch - 将反向 token 与自定义规范化器一起使用

python - Pandas groupby : group by semester

python - 暴力Python - OptParse 输出正确信息时遇到问题

elasticsearch - elasticsearch使用OR来查询多个词

c# - C#ElasticSearch通过嵌套列表元素属性比较获取外部对象

javascript - 使用 Node.js 将多个值插入或更新到 MySQL 表中

sql - 使用 Oracle 和 PL/SQL 插入或更新

mysql - Drupal 数据库 API 查询 - row.update 如果存在,否则 row.insert

python - 在 Django 中保存 unicode 字符串时出现 MySQL "incorrect string value"错误

python - PyDev运行配置: ImportError: No module named