Search in sources :

Example 1 with AnalyzeResponse

use of co.elastic.clients.elasticsearch.indices.AnalyzeResponse in project core-ng-project by neowu.

the class ElasticSearchTypeImpl method analyze.

@Override
public List<String> analyze(AnalyzeRequest request) {
    var watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    try {
        AnalyzeResponse response = elasticSearch.client.indices().analyze(builder -> builder.index(index).analyzer(request.analyzer).text(request.text));
        return response.tokens().stream().map(AnalyzeToken::token).toList();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (ElasticsearchException e) {
        throw elasticSearch.searchException(e);
    } finally {
        long elapsed = watch.elapsed();
        ActionLogContext.track("elasticsearch", elapsed);
        logger.debug("analyze, index={}, analyzer={}, elapsed={}", index, request.analyzer, elapsed);
        checkSlowOperation(elapsed);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ElasticsearchException(co.elastic.clients.elasticsearch._types.ElasticsearchException) AnalyzeResponse(co.elastic.clients.elasticsearch.indices.AnalyzeResponse) StopWatch(core.framework.util.StopWatch)

Aggregations

ElasticsearchException (co.elastic.clients.elasticsearch._types.ElasticsearchException)1 AnalyzeResponse (co.elastic.clients.elasticsearch.indices.AnalyzeResponse)1 StopWatch (core.framework.util.StopWatch)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1