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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…