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

查看:41
本文介绍了如何在 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天全站免登陆