【问题标题】:Spring data elasticsearch bulk index on PercolatorPercolator 上的 Spring 数据弹性搜索批量索引
【发布时间】:2021-08-16 01:23:09
【问题描述】:

使用 spring data elasticsearch 我想做以下(批量索引)

第 1 步

PUT surname
{
   "settings" : {
                "index" : {
                  "number_of_shards" : 1,
                  "number_of_replicas" : 0
                }
              },
            "mappings": {
                "properties": {
                  "message": {
                    "type": "text"
                  },
                  "query": {
                    "type": "percolator"
                  }
                }
              }
}

第 2 步:

PUT surname/_bulk
{ "index" : { "_index" : "surname", "_type" : "_doc", "_id" : "1" } }
{ "query" : { "match_phrase" : { "message" : "Aal" } }}
{ "index" : { "_index" : "surname", "_type" : "_doc", "_id" : "2" } }
{ "query" : { "match_phrase" : { "message" : "Aalbers" } }}

第 1 步在 - https://stackoverflow.com/a/67724048/4068218

的帮助下完成

对于第 2 步,我尝试了

IndexQuery 和 UpdateQuery

Query query = new CriteriaQuery(new Criteria("match_phrase").subCriteria(new Criteria("message").is("Aal")));
        UpdateQuery updateQuery = builder(query).build();
        elasticsearchOperations.bulkUpdate(ImmutableList.of(updateQuery),IndexCoordinates.of(indexName.get()));

但两者都不起作用。如果我使用 UpdateQuery 验证失败:1: id is missing;2: script or doc is missing.

如果我使用 IndexQuery,我会得到格式错误的查询。

spring data elasticsearch中的Step 2怎么做?非常感谢任何线索。

【问题讨论】:

    标签: java elasticsearch spring-data-elasticsearch


    【解决方案1】:

    以下代码对我有用。在这里分享,因为它可能对某人有帮助

    IndexQuery indexQuery = new IndexQueryBuilder()
                                            .withId("12")
                                            .withSource(String.format("{ \"query\" : { \"match_phrase\" : { \"message\" : \"%s\" } }}", "Aal"))
                                            .build();
    
            elasticsearchOperations.bulkIndex(ImmutableList.of(indexQuery),IndexCoordinates.of(indexName.get()));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 2016-06-20
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 2013-10-16
      • 2021-01-01
      • 2017-10-22
      相关资源
      最近更新 更多