我不确定我是否在批量索引中正确使用了 upsert
操作。
我的要求是:
{ "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
我想我在 documentation 中遗漏了一些东西但我仍然找不到如何进行此操作。
我想要的是在索引中创建上面的文档或者如果存在则更新它。
最佳答案
如果您通过批量 API 将记录添加到索引中
{ "create": {"_id": "someId"}}\n
{"id":"someId","uri":"/0/1/3/2/1/0511912310/511912310.xml"}\n
然后如果该 id 已经存在于索引中,您将得到一个异常。 如果您想添加或替换一个文档(取决于它是否存在),您应该按照以下方式执行请求
{ "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/en/elasticsearch/reference/current/docs-bulk.html version 5.3
关于ElasticSearch 批量插入/更新操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24651596/