0

I am new to ElasticSearch (ES). Day one on the java high level API.

I understand that POST a document allows ES to auto-generate the document ID. PUT allows me to use a pre-existing ID.

From the API docs here, I am not sure how to differentiate between the two approaches when indexing a new document. I wish to use the POST approach.

2
  • 1
    You want to use the POST approach as in you don't want to specify the ID? The title says "with know ID". Commented Feb 19, 2019 at 21:58
  • tks for the heads up Commented Feb 20, 2019 at 1:06

1 Answer 1

1

The Java API has an overloaded IndexRequest constructor. If you don't want to specify the ID, you don't have to.

public IndexRequest(String index, String type) {
    ...
}

public IndexRequest(String index, String type, String id) {
    ...
}

Presumably the former is a POST request and the latter is a PUT.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.