【问题标题】:How to set OpType on IndexQuery in Spring Data Elasticsearch如何在 Spring Data Elasticsearch 中的 IndexQuery 上设置 OpType
【发布时间】: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


    【解决方案1】:

    Spring Data ES 目前不支持此功能。

    有一个未解决的问题准确地报告了该功能,您可能想查看一下:https://jira.spring.io/browse/DATAES-247

    【讨论】:

    • 所以我想我必须使用 Elasticsearch Java API 来实现这一点。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多