【发布时间】:2019-04-02 09:53:54
【问题描述】:
假设 spring-boot-starter-data-elasticsearch 版本为 2.1.0.RC1。
采用以下简单的实现来索引实体:
IndexQuery indexQuery = new IndexQueryBuilder().withId(entity.getId()).withObject(entity).build();
String id = elasticsearchTemplate.index(indexQuery);
如何在此操作上设置 OpType.CREATE,以确保仅对不存在的文档进行索引?
等效的 REST API 请求如下所示:
POST /{index}/{entity id}?op_type=create
{
"id" : "{entity id}",
"attribute" : "value"
}
【问题讨论】:
标签: elasticsearch spring-data spring-data-elasticsearch