代码之家  ›  专栏  ›  技术社区  ›  Rohanil

使用批量API将批次追加到elasticsearch存储中

  •  0
  • Rohanil  · 技术社区  · 7 年前

    我有大量的文档,它们具有相同的索引和相同的类型,但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 回复  |  直到 7 年前
        1
  •  2
  •   Val    7 年前

    你需要这样做:

    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 对于要批量更新的每个文档。