王子1*_*986 7 elasticsearch spring-boot
我正在尝试在Spring Boot应用程序中进行弹性搜索,并且想对ElasticsearchRepository执行的查询进行调试。
尝试过,
logging.level.org.elasticsearch.index.search.slowlog.query=INFO
spring.data.elasticsearch.properties.index.search.slowlog.threshold.query.info=1ms
但我没有在日志中看到查询打印
使用 Springboot 2.2.6 和RestHighLevelClient
,执行以下操作:
logging.level.org.springframework.data.elasticsearch.client.WIRE : trace
Run Code Online (Sandbox Code Playgroud)
这也记录在springboot-data-elasticsearch
但是,您需要注意以RestHighLevelClient
文档中所述的相同方式初始化您的bean。即,使用ClientConfiguration
构建器。起初我创建了 bean new RestHighLevelClient()
,但它不起作用。例子:
logging.level.org.springframework.data.elasticsearch.client.WIRE : trace
Run Code Online (Sandbox Code Playgroud)
我尝试了其他答案,但它在 spring boot 2.2.2 和 elasticsearch 6.7.2 中不起作用,下面的内容对我有用可能是因为我使用 ,RestHighLevelClient
来获取请求和响应正文,我必须在中启用 apache http 日志记录application.properties 文件如下
logging.level.org.elasticsearch.client=TRACE
logging.level.org.apache.http=TRACE
Run Code Online (Sandbox Code Playgroud)
在 Spring Boot 2 中,您可以使用以下命令启用查询调试:
logging.level.org.springframework.data.elasticsearch.core=DEBUG
Run Code Online (Sandbox Code Playgroud)
生成的日志将类似于:
{
"from" : 0,
"size" : 10,
"query" : {
"bool" : {
"must" : [
{
"query_string" : {
"query" : "some string",
"fields" : [
"nome^1.0"
],
"use_dis_max" : true,
"tie_breaker" : 0.0,
"default_operator" : "and",
"auto_generate_phrase_queries" : false,
"max_determinized_states" : 10000,
"enable_position_increments" : true,
"fuzziness" : "AUTO",
"fuzzy_prefix_length" : 0,
"fuzzy_max_expansions" : 50,
"phrase_slop" : 0,
"escape" : false,
"split_on_whitespace" : true,
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"version" : true
}
Run Code Online (Sandbox Code Playgroud)
此致。
归档时间: |
|
查看次数: |
1206 次 |
最近记录: |