我有大量的文档,它们具有相同的索引和相同的类型,但id却明显不同。我想更新现有的或批量插入新的。如何使用批量索引API实现它?我想做下面的事情,但是会引发错误。基本上,我想批量添加具有相同索引和相同类型的多个文档。
curl -s -H "Content-Type: application/json" -XPOST localhost:9200/_bulk -d'
{ "index": {"_type": "sometype", "_index": "someindex"}}
{ "_id": "existing_id", "field1": "test1"}
{ "_id": "existing_id2", "field2": "test2"}
'
最佳答案
您需要这样做:
curl -s -H "Content-Type: application/json" -XPOST localhost:9200/someindex/sometype/_bulk -d'
{ "index": {"_id": "existing_id"}}
{ "field1": "test1"}
{ "index": {"_id": "existing_id2"}}
{ "field2": "test2"}
'
由于所有文档的索引/类型都相同,因此将其移至URL并仅为要批量更新的每个文档指定
_id
。
关于elasticsearch - 使用批量API将批处理上传到Elasticsearch存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45323691/