[英]ElasticSearch: Java High Level API - Index doc with dynamic ID
I am new to ElasticSearch (ES). 我是ElasticSearch(ES)的新手。 Day one on the java high level API.
第一天使用Java高级API。
I understand that POST a document allows ES to auto-generate the document ID. 我知道POST文档可以使ES自动生成文档ID。 PUT allows me to use a pre-existing ID.
PUT允许我使用预先存在的ID。
From the API docs here , I am not sure how to differentiate between the two approaches when indexing a new document. 从此处的API文档,我不确定在索引新文档时如何区分这两种方法。 I wish to use the POST approach.
我希望使用POST方法。
The Java API has an overloaded IndexRequest constructor. Java API具有重载的IndexRequest构造函数。 If you don't want to specify the ID, you don't have to.
如果您不想指定ID,则不必。
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. 大概前者是POST请求,而后者是PUT。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.