0

我擁有大量具有相同索引和相同類型,但ID明顯不同的文檔。我想要更新現有的或批量插入新的。我怎樣才能使用批量索引API來實現它?我想要做下面的事情,但會引發錯誤。基本上,我想批量插入具有相同索引和相同類型的多個文檔。使用批量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"} 
' 
+0

在這裏你去https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html – anekix

+0

@anekix:謝謝,但文檔不包含我想要的。 – Rohanil

回答

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

由於所有的文件都在同一個索引/類型,將其移至URL和唯一指定_id您要更新的每個文檔在你的批量。