I'm new to Elastic search and I'm doing a task in which I need to upload more number of documents to ES. Whenever I upload everytime, I need to specify document id for that document in IndexRequest api. Is there any way in java so that i can insert documents without giving id for it (i.e creating random document id's for my documents).
Asked
Active
Viewed 1,894 times
-2
-
Are you using some kind of framework (spring data for example) or the elastic rest client directly? – ibexit Jul 05 '21 at 09:56
-
@ibexit I'm using servlets for elastic high level rest clients – Ajay Venkatesh Jul 05 '21 at 09:59
1 Answers
1
Please have a look at https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.13/java-rest-high-document-index.html
In order to have the id autogenerated, just ommit this call:
request.id("1");
This should do the trick for single document operations.
If you need bulk changes, see https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html
In this case, also remove the .id("1") method call.

ibexit
- 3,465
- 1
- 11
- 25