gpt4 book ai didi

elasticsearch - 如何知道DSL Elasticsearch解析的最终查询?

转载 作者:行者123 更新时间:2023-12-03 01:44:18 25 4
gpt4 key购买 nike

我知道以下两个查询可以得到相同的结果。但是有没有办法查看Elasticsearch最终解析的查询,所以我当然可以知道它们是相同的吗? (或者,它们实际上并不完全相同,也许一个时间比另一个时间少?)

查询1:

GET /_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"price": 20
}
}
}
}
}

查询2:
GET /_search
{
"query": {
"term": {
"price": 20
}
}
}

最佳答案

为了测试和分析查询,您可以使用Slow Log,它允许将查询和获取阶段记录到日志文件中。它是高度可配置的-您可以定义每个索引的“慢查询”含义。

名为“sample”的索引的简单示例(出于测试目的,它将在时间设置为“0s”的情况下进行记录-您可以设置自己的阈值):

首先关闭索引:

curl -X POST http://127.0.0.1:9200/sample/_close

然后配置慢速日志:
curl -X PUT \
'http://127.0.0.1:9200/sample/_settings?preserve_existing=true' \
-d '{
"index.indexing.slowlog.threshold.index.debug" : "0s",
"index.search.slowlog.threshold.fetch.debug" : "0s",
"index.search.slowlog.threshold.query.debug" : "0s"
}'

打开索引:
curl -X POST http://127.0.0.1:9200/sample/_open

在执行您在帖子中提供的较短查询之后(我有5个分片,并且针对每个分片执行查询):
[index.search.slowlog.query] [sample][1] took[594.1micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
[index.search.slowlog.query] [sample][3] took[649.4micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}],
[index.search.slowlog.query] [sample][4] took[575.6micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}],
[index.search.slowlog.query] [sample][2] took[1.2ms], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}],
[index.search.slowlog.query] [sample][0] took[4.3ms], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}],
...

执行较长的查询后,您在帖子中提供了以下内容:
[index.search.slowlog.query] [sample][1] took[13.2ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
[index.search.slowlog.query] [sample][4] took[13.2ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}],
[index.search.slowlog.query] [sample][3] took[14.7ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}],
[index.search.slowlog.query] [sample][2] took[15.5ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}],
[index.search.slowlog.query] [sample][0] took[15.5ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}],
...

当然,这只是一次尝试,但对于更深入的测试和分析可能非常有用。

关于elasticsearch - 如何知道DSL Elasticsearch解析的最终查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45231349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com