ElasticSearch bulk insert/update operation

前端 未结 2 1071
孤街浪徒
孤街浪徒 2021-02-07 07:35

I am not sure if I am using correctly the upsert operation in bulk indexing.

My request is:

{ \"update\": {\"_id\": \"610946100\"}}\\n
{\"do         


        
2条回答
  •  梦如初夏
    2021-02-07 07:55

    If you add records in the index via the bulk API as

    { "create": {"_id": "someId"}}\n
    {"id":"someId","uri":"/0/1/3/2/1/0511912310/511912310.xml"}\n
    

    then if the id already exists in the index you will get an exception. If you want to either add or replace a document (depending on whether it exists or not), you should do the request as

    { "index": {"_id": "someId"}}\n
    {"id":"someId","uri":"/0/1/3/2/1/0511912310/511912310.xml"}\n
    

    create will fail if a document with the same index and type exists already, whereas index will add or replace a document as necessary

    https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html version 5.3

提交回复
热议问题