我正在尝试调试ElasticSearch查询。我已经为有问题的查询启用了explain,这表明查询正在做一个中间分数的乘积,该分数应该是总和。 (我正在使用elastic4s创建查询请求。)
问题是我看不到生成的查询实际上是什么。我想确定该错误是否存在于Elastic4s(错误地生成查询请求),我的代码中或Elasticsearch中。因此,我已使用以下代码为测试中使用的嵌入式elasticsearch实例启用日志记录:
ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory())
val settings = Settings.settingsBuilder
.put("path.data", dataDirPath)
.put("path.home", "/var/elastic/")
.put("cluster.name", clusterName)
.put("http.enabled", httpEnabled)
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put("discovery.zen.ping.multicast.enabled", false)
.put("index.refresh_interval", "10ms")
.put("script.engine.groovy.inline.search", true)
.put("script.engine.groovy.inline.update", true)
.put("script.engine.groovy.inline.mapping", true)
.put("index.search.slowlog.threshold.query.debug", "0s")
.put("index.search.slowlog.threshold.fetch.debug", "0s")
.build
但我在logback.xml中配置的日志文件中找不到正在记录的任何查询。来自Elasticsearch的其他日志消息出现在此处,而不仅仅是实际查询。
最佳答案
您不能,至少不能直接,至少不能在当前可用的ES版本中。已经讨论了一些内容(例如https://github.com/elastic/elasticsearch/issues/9172和https://github.com/elastic/elasticsearch/issues/12187),似乎随着重写任务API可能会很快改变。同时,您可以使用ES ReSTLog(https://github.com/etsy/es-restlog)之类的东西和/或将nginx放在ES的前面,并在nginx日志中捕获查询。您还可以使用tcpdump(例如tcpdump -vvv -x -X -i any port 9200
)并在服务器上运行查询时捕获该查询。最后一种选择是修改应用程序并回显查询,而不是执行查询(和/或在执行查询之前将查询插入ES本身,因为查询本身是JSON)。