How to enable query logging in Spring-data-elasticsearch How to enable query logging in Spring-data-elasticsearch elasticsearch elasticsearch

How to enable query logging in Spring-data-elasticsearch


This one is quite old, but I'd still like to share the solution that worked for me. To log Spring Data Elasticsearch queries executed through the Repository, you need to enable DEBUG logging for the package org.springframework.data.elasticsearch.core.*, e.g. as follows:

logging:  level:    org:      springframework:        data:          elasticsearch:            core: DEBUG

After that, queries will appear in logs:

{  "from" : 0,  "size" : 1,  "query" : {    "bool" : {      "should" : [ {        "query_string" : {          "query" : "John Doe",          "fields" : [ "entityName" ],          "default_operator" : "and"        }      }, {        "query_string" : {          "query" : "John Doe",          "fields" : [ "alias" ],          "default_operator" : "and"        }      } ]    }  },  "post_filter" : {    "bool" : { }  }}

One would expect an elegant solution similar to JPA, but it seems that it doesn't simply exist.

Tested with Spring Boot 1.4.0 and Spring Data Elasticsearch 1.7.3.


After digging through the spring data code i found this helpful little logger called "tracer" (name not very unique)

By setting the following in application.properties

logging.level.tracer=TRACE

It will print out a full curl statement for the request along with full JSON the response from Elasticsearch.


If you are using spring boot you can set the following in your application.properties:

logging.level.org.elasticsearch.index.search.slowlog.query=INFOspring.data.elasticsearch.properties.index.search.slowlog.threshold.query.info=1ms