-
Notifications
You must be signed in to change notification settings - Fork 1.3k
DATAES-317 - Introduce query logging in ElasticsearchTemplate. #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
930b702
to
0919dab
Compare
3b425e9
to
5db9b45
Compare
@akonczak a +1 or -1 would be nice from your side. Currently the search query is only logged in |
|
||
private SearchResponse getSearchResponse(SearchRequestBuilder requestBuilder) { | ||
if (QUERY_LOGGER.isDebugEnabled()) | ||
QUERY_LOGGER.debug(requestBuilder.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if Spring has any guidelines for this, but I found this old document recommending to include curly-braces around if statements - http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html
@@ -136,7 +137,8 @@ | |||
*/ | |||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware { | |||
|
|||
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchTemplate.class); | |||
private static final Logger QUERY_LOGGER = LoggerFactory.getLogger("org.springframework.data.elasticsearch.core.QUERY"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, though I don't know if there are any conventions within Spring / Spring Data to look towards following for this type of logging? For example in the JPA project they have the following options for logging queries - http://www.baeldung.com/sql-logging-spring-boot
Original pull request: #180.
Original pull request: #180.
I've polished and merged that for Lovelace and Kay. |
@olivergierke thanks 👍 |
The java client of elasticsearch does not provide an easy way to log the serialized query (JSON) by setting the log level of some logger to DEBUG. Therefore this PR adds logging capability to the ElasticsearchTemplate because it enclose the ES
SearchRequestBuilder
where you need to calltoString()
to get the real JSON query.The logging is done by a separate logger
org.springframework.data.elasticsearch.core.QUERY
which needs to be set to log level DEBUG to output the serialized query.