【问题标题】:How can I use Analyze API in spring data elasticsearch?如何在 spring data elasticsearch 中使用 Analyze API?
【发布时间】:2023-03-22 13:39:02
【问题描述】:

伙计们,

我想执行 - GET /_analyze 以使用 spring-data-elasticsearch

根据分析器进行标记化

我在 spring-data-elasticsearch 中看到了 RequestConverters.analyze()。因此我能够做到以下几点

AnalyzeRequest analyzeRequest = AnalyzeRequest.withGlobalAnalyzer("stop", payload);
        Request request = RequestConverters.analyze(analyzeRequest);

上面构建了一个请求,但是我如何使用上面的请求让 spring-data-elasticsearch 调用弹性搜索?

我检查了 ElasticsearchRestTemplate 甚至 RestHighLevelClient,但其中没有一个公共方法将 Request 作为参数。

非常感谢任何潜在客户。谢谢

【问题讨论】:

    标签: spring spring-data spring-data-elasticsearch


    【解决方案1】:

    回答我自己的问题,因为这可能对其他人有帮助。

    我做了以下操作来获取令牌

         AnalyzeRequest analyzeRequest = AnalyzeRequest.withGlobalAnalyzer("stop", payload);
                AnalyzeResponse response = elasticSearchRestClientConfig.elasticsearchClient().indices().analyze(analyzeRequest, RequestOptions.DEFAULT);
      List<AnalyzeResponse.AnalyzeToken> tokens = response.getTokens();
        
    

    【讨论】:

      【解决方案2】:

      假设您使用ElasticsearchRestTemplate 设置ElasticsearchOperations,则无需创建新客户端即可执行以下操作:

          AnalyzeRequest request = AnalyzeRequest.withGlobalAnalyzer("stop", "some text to analyse");
          ElasticsearchRestTemplate restTemplate = (ElasticsearchRestTemplate) this.operations;
          AnalyzeResponse analyzeResponse = restTemplate.execute(client -> client.indices().analyze(request, RequestOptions.DEFAULT));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-23
        • 1970-01-01
        • 2014-08-19
        • 2020-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多