记录通过ElasticSearch高级Java客户端构建的JSON查询以进行调试? [英] log JSON queries built through ElasticSearch High Level Java Client for debugging?
问题描述
我在Spring Boot应用程序中使用ElasticSearch高级客户端Java API.我想记录使用高级客户端API构建的查询,以进行调试.
I use ElasticSearch High-Level Client Java API in my Spring Boot application. I want to log the queries built using High-Level client API for debugging purposes.
我的问题是我的application.properties文件中需要什么样的设置才能打开从我的应用程序构建的JSON查询?
My question is what kind of settings required in my application.properties file to turn on JSON queries built from my application?
我尝试了以下属性到application.properties文件.但是,它不会打印使用各种查询构建器构建的JSON查询.
I tried out the following properties to the application.properties file. However, it does not print the JSON queries built using various query builders.
logging.level.org.elasticsearch.client=TRACE
logging.level.org.elasticsearch.client.sniffer=TRACE
logging.level.org.elasticsearch=TRACE
推荐答案
您只需在记录器中使用以下代码,即可记录使用高级客户端生成的查询.
You can simply log the queries built using the rest-high level client, using the below code in your logger.
您还可以控制要记录的查询类型以及在特定情况下要设置的级别(TRACE,INFO,DEBUG).
SearchRequest searchRequest = new SearchRequest("employee").source(sourceBuilder);
log.info("Search JSON query: {}", searchRequest.source().toString());
第一行用于创建搜索请求,第二行用于打印搜索JSON
,请注意 searchRequest.source().toString())
用于获取搜索JSON字符串.
The first line, is used to create a search request and second line is used to print the search JSON
, Note searchRequest.source().toString())
which is used to get the search JSON string.
如果您遇到任何问题,请告诉我,我一直在使用高级客户进行操作.
Let me know if you face any issue, I do this all the time using the rest-high-level client.
这篇关于记录通过ElasticSearch高级Java客户端构建的JSON查询以进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!