Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

xhaggi
Copy link
Contributor

@xhaggi xhaggi commented Mar 28, 2017

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 call toString() 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.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@xhaggi xhaggi force-pushed the query-logging branch 2 times, most recently from 930b702 to 0919dab Compare April 5, 2017 09:13
@xhaggi xhaggi changed the title [DATAES-317] introduce query logging in ElasticsearchTemplate DATAES-317 - introduce query logging in ElasticsearchTemplate Jun 22, 2018
@xhaggi xhaggi force-pushed the query-logging branch 2 times, most recently from 3b425e9 to 5db9b45 Compare June 22, 2018 15:14
@xhaggi
Copy link
Contributor Author

xhaggi commented Jun 22, 2018

@akonczak a +1 or -1 would be nice from your side. Currently the search query is only logged in queryForPage https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java#L366 and that's only half way around.

@xhaggi xhaggi changed the title DATAES-317 - introduce query logging in ElasticsearchTemplate DATAES-317 - Introduce query logging in ElasticsearchTemplate. Jun 25, 2018

private SearchResponse getSearchResponse(SearchRequestBuilder requestBuilder) {
if (QUERY_LOGGER.isDebugEnabled())
QUERY_LOGGER.debug(requestBuilder.toString());

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");

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

odrotbohm pushed a commit that referenced this pull request Jun 28, 2018
odrotbohm pushed a commit that referenced this pull request Jun 28, 2018
@odrotbohm
Copy link
Member

I've polished and merged that for Lovelace and Kay.

@odrotbohm odrotbohm closed this Jun 28, 2018
@xhaggi
Copy link
Contributor Author

xhaggi commented Jun 28, 2018

@olivergierke thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants