使用批量API将批次上传到elasticsearch商店

时间:2017-07-26 10:02:44

标签: elasticsearch elasticsearch-bulk-api elasticsearch-bulk

我有大量具有相同索引和相同类型的文档,但显然有不同的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"}
'

1 个答案:

答案 0 :(得分:2)

你需要这样做:

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"}
'

由于所有文档都使用相同的索引/类型,因此请将其移至网址,并仅为批量更新的每个文档指定_id