Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Unique field

I want to store urls in an index but I want unique url.

I'm making POST request to store my documents but I want to avoid duplicate document based on the url field.

Is there a way to specify a unique constraint on the url field ?

I have around 5 million of data so I don't want to make url as the document ID instead as it will slowdown my search query.

like image 954
Ironman Avatar asked Nov 10 '22 20:11

Ironman


1 Answers

No, the _id is the only field that can have the uniqueness restriction. You probably know this but a new document with existing id would override the existing document with same id. You can use op_type=create or /my_index/my_type/ID/_create in order to get back an error if a document with same id already exists.

like image 62
Andrei Stefan Avatar answered Nov 15 '22 08:11

Andrei Stefan