gpt4 book ai didi

php - _score,同时在Elasticsearch中进行索引

转载 作者:行者123 更新时间:2023-12-03 02:09:23 24 4
gpt4 key购买 nike

{
"query": {
"custom_score": {
"query": {
"match": {
"xxx": {
"query": "foobar"
}
}
},
"filter": {
"and": [
{
"query": {
"match": {
"yyyy": {
"query": "barfoo"
}
}
}
}
]
}
},
"script": "_score * doc['_score']"
}
}

这给出了错误
 [custom_score] query does not support [filter]

那么如何评估这样的查询呢?

最佳答案

我建议您查看有关提升的要求,因为当前的脚本没有多大意义。

另外,请参阅elasticsearch query DSL的文档。它提供复合查询和简单查询,您可以将它们组合在一起。如错误所述,您不能在自定义分数查询中放入过滤器。您可以在自定义分数查询中使用filtered query:

{
"query": {
"custom_score": {
"query": {
"filtered" : {
"query" : {
"match": {
"xxx": {
"query": "foobar"
}
}
},
"filter" : {
"and": [
{
"query": {
"match": {
"yyyy": {
"query": "barfoo"
}
}
}
}
]
}
}
},
"script": "_score * doc['_score']"
}
}
}

或像这样使用顶级 filter:
{
"query": {
"custom_score": {
"query": {
"match": {
"xxx": {
"query": "foobar"
}
}
},
"script": "_score * doc['_score']"
}
},
"filter": {
"and": [
{
"query": {
"match": {
"yyyy": {
"query": "barfoo"
}
}
}
}
]
}
}

这两个选项之间的区别在于,如果您在搜索请求中也进行了构面,则不会考虑使用顶级过滤器,而如果将过滤器放入查询中,则会考虑它们。

另一件事要看:如果只有一个子句,则不需要and过滤器。同样,在过滤器中放置全文搜索通常没有意义,因为过滤器是可缓存的,并且鉴于全文搜索是免费的并且几乎是不可预测的,因此缓存它们是浪费的。

关于php - _score,同时在Elasticsearch中进行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17467135/

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