简体   繁体   English

渗滤器上的 Spring 数据 elasticsearch 批量索引

[英]Spring data elasticsearch bulk index on Percolator

Using spring data elasticsearch I want to do the following (bulk Indexing)使用 spring 数据 elasticsearch 我想做以下(批量索引)

Step 1步骤1

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

Step 2:第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" } }}

Step 1 is done with the help of - https://stackoverflow.com/a/67724048/4068218步骤 1https://stackoverflow.com/a/67724048/4068218的帮助下完成

For Step 2 I tried对于第 2 步,我尝试了

IndexQuery and 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()));

but both do not work.但两者都不起作用。 If I use UpdateQuery I get Validation Failed: 1: id is missing;2: script or doc is missing.如果我使用 UpdateQuery ,我会得到验证失败:1:缺少 id;2:缺少脚本或文档。

If I use IndexQuery I get malformed query.如果我使用 IndexQuery,我会得到格式错误的查询。

How do I go about Step 2 in spring data elasticsearch?我如何 go 关于 spring 数据 elasticsearch 中的第 2 步 Any lead is much appreciated.非常感谢任何线索。

Below code worked for me.下面的代码对我有用。 Sharing here as it might help someone在这里分享,因为它可能对某人有帮助

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()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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