如何在Spring-data-elasticsearch中启用查询日志记录 [英] How to enable query logging in Spring-data-elasticsearch

查看:3006
本文介绍了如何在Spring-data-elasticsearch中启用查询日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用spring-data-elasticsearch框架从elasticsearch服务器获取查询结果,java代码如下:

I use spring-data-elasticsearch framework to get query result from elasticsearch server, the java code like this:

SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery()).withSearchType(SearchType.COUNT)
.addAggregation(new MinBuilder("min_createDate").field("createDate"))
.build();

List<Entity> list = template.queryForList(searchQuery, Entity.class);

虽然如何知道发送给elasticssearch服务器的原始http查询?
如何启用日志记录,我尝试添加log4j,但似乎spring-data-elasticsearch不会记录查询。

While how can I know the raw http query sent to elasticssearch server? How can I enable the logging, I tried add log4j, but it seems the spring-data-elasticsearch doesn't log the query.

推荐答案

我没有Spring Data Elasticsearch的答案,但在ES本身,您可以提高慢速查询日志记录的默认设置,并查看慢速日志中的所有查询。有关慢速日志此处的更多详细信息。

I don't have an answer for Spring Data Elasticsearch, but in ES itself you can bump up the default settings for slow query logging and see all the queries in the slow log. More details about slow log here.

关于如何更改阈值,应使用如下命令:

As to how to change the thresholds, a command like this should be used:

PUT /_settings
{
  "index.search.slowlog.threshold.query.info": "1ms"
}

1ms 是您可以设置的最小值。

1ms is kindof the smallest value you can set.

这篇关于如何在Spring-data-elasticsearch中启用查询日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆