How to create unique constraint in Elasticsearch database?

前端 未结 5 1607
别那么骄傲
别那么骄傲 2020-12-01 18:02

I am using elasticsearch as a document database and each record I create has a guid id that the system uses for the record id. Business people want to offer a feature to let

5条回答
  •  广开言路
    2020-12-01 19:09

    You'd need to use the field that is supposed to be unique as id for your documents. By default a new document with existing id would override the existing document with same id, but you can switch to op_type=create in order to get back an error if a document with same id already exists.

    There's no way to have the same behaviour with arbitrary fields though, only the _id field works that way. I would probably consider handling this logic in the application layer instead of within elasticsearch.

提交回复
热议问题