ElasticSearch批量插入/更新操作 [英] ElasticSearch bulk insert/update operation
问题描述
我不确定是否在批量索引编制中正确使用了 upsert
操作。
I am not sure if I am using correctly the upsert
operation in bulk indexing.
我的请求是:
{ "update": {"_id": "610946100"}}\n
{"doc": {"id":"610946100","uri":"/0/0/1/6/4/0/610946100.xml"}, "doc_as_upsert" : true}\n
,URL为: http:// localhost:9200 / anIndex / aType / _bulk
我想我错过了文档,但我仍然找不到如何执行此操作的方法。
I guess I missed something in the documentation but I still can't find how to make this operation.
我想要的是创建
推荐答案
如果通过批量在索引中添加记录API为
If you add records in the index via the bulk API as
{ "create": {"_id": "someId"}}\n
{"id":"someId","uri":"/0/1/3/2/1/0511912310/511912310.xml"}\n
然后,如果索引中已经存在ID,您将获得异常。
如果您想添加或替换文档(取决于文档是否存在),则应以
then if the id already exists in the index you will get an exception. If you want to either add or replace a document (depending on whether it exists or not), you should do the request as
{ "index": {"_id": "someId"}}\n
{"id":"someId","uri":"/0/1/3/2/1/0511912310/511912310.xml"}\n
如果具有相同索引和类型的文档已经存在
,则创建将失败,而索引将根据需要添加或替换文档
create will fail if a document with the same index and type exists already, whereas index will add or replace a document as necessary
https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/ docs-bulk.html 版本5.3
这篇关于ElasticSearch批量插入/更新操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!