Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show elasticsearch queries in spring boot application

I am trying elastic search in spring boot application and I would like to debug on queries executed by ElasticsearchRepository.

tried logging.level.org.elasticsearch.index.search.slowlog.query=INFO spring.data.elasticsearch.properties.index.search.slowlog.threshold.query.info=1ms but I didn't see the query print in log

like image 992
王子1986 Avatar asked Mar 23 '17 02:03

王子1986


People also ask

Why ElasticsearchTemplate is deprecated?

The ElasticsearchTemplate class is deprecated as it uses the TransportClient to access Elasticsearch, which itself is deprecated since Elasticsearch version 7.

Does Elasticsearch use spring?

Spring Data for Elasticsearch is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for for new datastores while retaining store-specific features and capabilities.

Is Elasticsearch reactive?

ElasticSearch is well known as a search engine, also working well as document based NoSQL. Spring Data ElasticSearch adds basic Reactive support.


1 Answers

Using Springboot 2.2.6, and RestHighLevelClient, the following worked:

logging.level.org.springframework.data.elasticsearch.client.WIRE : trace

This is also documented in springboot-data-elasticsearch

However, you need to pay attention to initialize your RestHighLevelClient bean in the same way stated in the documentation. I.e, using the ClientConfiguration builder. At first I created the bean as new RestHighLevelClient() and it didn't work. Example:

    @Bean(destroyMethod = "close")
    public RestHighLevelClient restClient() {

        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(esHost +":" + esPort).usingSsl()
                .build();

        RestHighLevelClient client = RestClients.create(clientConfiguration).rest();
        return client;

    }

like image 118
orid Avatar answered Sep 21 '22 09:09

orid