简体   繁体   中英

ElasticSearch: Java High Level API - Index doc with dynamic ID

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM