gpt4 book ai didi

Elasticsearch 首先返回精确匹配,然后返回其他匹配

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

我有一些 PageDocument,我想根据标题进行搜索,不包括路径以某些特定文本开头的 PageDocument。这个领域进行了分析。我想要一些模糊性来帮助用户解决拼写错误。我需要能够进行部分匹配,以便 some 匹配 some textthis is some text

如果我使用以下查询,由于 tf-idf,我不会得到第一个结果的精确匹配

{
"size": 20,
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/test/*"
}
}
}
]
}
}
}

然后我在 title.not_analyzed 处添加了一个 not_analyzed 版本的标题字段,并尝试添加一个函数 score 以使用 增加精确匹配的权重术语

{
"query": {
"function_score": {
"functions": [
{
"weight": 2,
"filter": {
"fquery": {
"query": {
"term": {
"title.not_analyzed": {
"value": "myterm"
}
}
}
}
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/path/*"
}
}
}
]
}
},
"boost_mode": "multiply"
}
}
}

但这给了我相同的结果。如何获得最先返回的完全匹配项?

最佳答案

我们通过添加 shouldboost 的组合找到了解决方案。

{
"size": 20,
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/path/*"
}
}
}
],
"should": [
{
"term": {
"title": {
"value": "myterm",
"boost": 10
}
}
}
]
}
}
}

关于Elasticsearch 首先返回精确匹配,然后返回其他匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41898447/

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