gpt4 book ai didi

nest - 将文档批量插入文档到ElasticSearch中而无需更新

转载 作者:行者123 更新时间:2023-12-02 22:32:49 30 4
gpt4 key购买 nike

如果Id存在,是否可以将批量将数据插入ES而不更新文档内容。仅不应插入现有文档,而无需进行任何更新。

最佳答案

是的,使用批量create:

POST /my_index/my_type/_bulk
{"create":{"_id":1}}
{"foo":1,"bar":"y"}
{"create":{"_id":6}}
{"foo":1,"bar":"y"}

上面的请求是针对已经存在的doc 1和不存在的doc 6。该请求的输出为:
"items": [
{
"create": {
"_index": "my_index",
"_type": "my_type",
"_id": "1",
"status": 409,
"error": "DocumentAlreadyExistsException[[my_index][2] [my_type][1]: document already exists]"
}
},
{
"create": {
"_index": "my_index",
"_type": "my_type",
"_id": "6",
"_version": 1,
"status": 201
}
}
]

关于nest - 将文档批量插入文档到ElasticSearch中而无需更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29968953/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com