gpt4 book ai didi

Elasticsearch - 对没有特定字段的文档给予负面提升

转载 作者:行者123 更新时间:2023-11-29 02:47:46 24 4
gpt4 key购买 nike

我正在处理一个查询,基本的过滤多重匹配查询按计划工作,它返回我想要的文档。

问题是想要提升具有 ex 的特定字符串字段的结果。 0.5,或者在本例中给出没有此字段“traded_as”的结果 1.0 的负提升。

无法让过滤器 - 提升 - 必须 - 存在/缺失才能按我的意愿工作。

这是解决这个问题的正确方法吗?

使用 Elasticsearch 1.5.2

{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "something",
"fields": ["title", "url", "description"]
}
},
"filter": {
"bool": {
"must": {
"missing": {
"field": "marked_for_deletion"
}
}
}
}
}
},
"boosting": {
"positive": {
"filter": {
"bool": {
"must": {
"exists": {
"field": "traded_as"
}
}
}
}
},
"negative": {
"filter": {
"bool": {
"must": {
"missing": {
"field": "traded_as"
}
}
}
}
},
"negative_boost": 1.0
}
}

最佳答案

你不可能得到想要的结果。正如提升查询的文档中所述:

Unlike the "NOT" clause in bool query, this still selects documents that contain undesirable terms, but reduces their overall score.

{
"query": {
"boosting": {
"positive": [{
"filtered": {
"query": {
"multi_match": {
"query": "something",
"fields": ["title", "url", "description"]
}
},
"filter": {
"bool": {
"must": [{
"missing": {
"field": "marked_for_deletion"
}
}]
}
}
}
}],
"negative": [{
"filtered": {
"filter": {
"missing": {
"field": "traded_as"
}
}
}
}],
"negative_boost": 1.0
}
}
}

所以你仍然会有一些不相关的文档,但是匹配的文档会有更好的分数。那样的话,您不会对 traded_as 存在有任何提升。为此,您应该查看函数得分 http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score

你会得到类似的东西

{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "something",
"fields": ["title", "url", "description"]
}
},
"filter": {
"bool": {
"must": {
"missing": {
"field": "marked_for_deletion"
}
}
}
}
}
},
"functions": [{
"filter": {
"exists": {
"field": "traded_as"
}
},
"boost_factor": 2
}, {
"filter": {
"missing": {
"field": "traded_as"
}
},
"boost_factor": 0.5
}],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}

关于Elasticsearch - 对没有特定字段的文档给予负面提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30097466/

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