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您要更新的每个文档在你的批量。