简体   繁体   English

如何在spring boot中使用弹性搜索模板id(存储在ES集群中)得到结果

[英]How to use elastic search template id(stored in ES cluster) in spring boot get result

I have an elastic search template stored in my ES we want to use this template-id in spring boot rest high client elastic search by passing the required parameter我在 ES 中存储了一个弹性搜索模板,我们希望通过传递所需的参数在 spring boot rest 高客户端弹性搜索中使用此模板 ID

curl -X POST \
  http://localhost:9200/_scripts/my_template_id \
  -H 'content-type: application/json' \
  -d '{
        "script": {
            "lang": "mustache",
            "source": {
              "query": {
                "bool": {
                  "should": [
                    {
                      "match": {
                        "studentName": {
                          "query": "{{query_string}}",
                          "operator": "or",
                          "fuzziness": 0,
                          "boost": 9
                        }
                      }
                    },
                    {
                      "match": {
                        "studentId": {
                          "query": "{{query_string}}",
                          "operator": "or",
                          "fuzziness": 0,
                          "boost": 1
                        }
                      }
                    }
                  ]
                }
              },
              "from": "{{from_offset}}",
              "size": "{{result_size}}"
            }
          }
      }'

I have tried multiple ways to make QuerySourceBuilder by using the above template id and get SearchResponse but I failed, Any suggestion why it's failing or spring boot doesn't support such a feature?我已经尝试了多种方法来使用上面的模板 id 制作 QuerySourceBuilder 并获得 SearchResponse 但我失败了,有什么建议为什么它失败或 spring boot 不支持这样的功能?

The next version of Spring Data Elasticsearch (4.3) will have support for searching with search template by using the NativeSearchQueryBuilder which then will have a method withSearchTemplate(SearchTemplateRequestBuilder searchTemplateBuilder) .下一版本的 Spring Data Elasticsearch (4.3) 将支持通过使用NativeSearchQueryBuilder使用搜索模板进行搜索,然后将有一个方法withSearchTemplate(SearchTemplateRequestBuilder searchTemplateBuilder)

Edit 02.08.2021: 2021 年 8 月 2 日编辑:

Having a deeper look at what is currently available, I noticed that having this on to the NativeSearchQuery is wrong.深入了解当前可用的内容后,我注意到将其添加到NativeSearchQuery是错误的。 We will need to change this to add a corresponding method to the ElasticseachOperations and the implementations.我们需要更改此设置以向ElasticseachOperations和实现添加相应的方法。

So in 4.3 there will be a solution, I will update this answer with details as sson as it's implemented.因此,在 4.3 中将有一个解决方案,我将使用 sson 的详细信息更新此答案,因为它已实施。

Edit 29.10.2021: 2021 年 10 月 29 日编辑:

won't be in 4.3, I have no capacity to implement this until release of 4.3, so it will be postponed.不会在 4.3 中,在 4.3 发布之前我没有能力实施它,所以它会被推迟。

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

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