gpt4 book ai didi

performance - Elasticsearch应该在没有计算相关性的情况下进行查询(_score)

转载 作者:行者123 更新时间:2023-12-02 22:57:11 25 4
gpt4 key购买 nike

我正在创建对两个字段进行操作的过滤查询。我想避免Elasticsearch的计算相关性。如何在不移至查询上下文的情况下实现OR语句。

我的简化模型有两个 bool(boolean) 字段:

{
is_opened,
is_send
}

我想用逻辑准备查询:
(is_opened == true AND is_send == true) OR (is_opened == false) 

换句话说,我要排除具有字段的文档:
is_opened == true AND is_send == false

我的查询如下所示:
GET documents/default/_search
{
"query": {
"bool": {
"should": [
{
"bool":{
"must":[
{"term": {"is_opened":true}},
{"term": {"is_send":true}}
]
}
},
{
"bool":{
"must":[
{"term": {"is_opened":false}}
]
}
}
]
}
}
}

从逻辑上讲,它按我的预期工作,但是Elasticsearch计算 相关性
我不需要它,因为最后我将结果按另一个字段排序,因此它是优化查询的地方。
我问这是因为 Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.

我的结果计算了_score字段,因此我认为上述查询是在查询上下文中执行的,因此Elasticsearch不会自动对其进行缓存。

将来,我想创建在状态字段上运行的查询,在该字段上逻辑会更加复杂。我仍然需要知道如何阻止计算_score。

我注意到更改应该过滤块计算_score,但必须作为运算符使用。是否可以更改过滤器行为?

是否可以使用其他查询?
如何强制Elasticserach停止计算_score?

最佳答案

只需将查询包装在 constant_score query中:

GET documents/default/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"is_opened": true
}
},
{
"term": {
"is_send": true
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"is_opened": false
}
}
]
}
}
]
}
}
}
}
}

关于performance - Elasticsearch应该在没有计算相关性的情况下进行查询(_score),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48903893/

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