使用布尔相似度或为弹性搜索中的特定查询实现类似的行为

问题描述 投票:0回答:1

我有100K个文档,其中只有50个具有alias属性。考虑以下两个文档:

doc1: 
{
   "name" : "FAC",// no alias property
}

doc2: 
{
   "name" : "some data",
   "alias" : [ "FCC"]
}

我正在使用以下多重匹配查询:

{
    "query": {
        "multi_match": {
            "query": "FCC",
            "type": "most_fields",
            "fuzziness": 1,
            "prefix_length": 0,
            "operator": "AND",
            "fields": [
                "alias",
                "name"
            ]
        }
    }
}

doc1 在响应中出现在 doc2 之前,这是意外的结果。 doc1 的分数比 doc2 更高,因为大多数文档中不存在别名属性。默认的相似度算法BM25使用boost、IDF和TF来计算分数。与 doc2 相比,doc1 的 IDF 更高,因为它取决于属性。我可以使用布尔相似度来实现预期的行为,但我不想更新布尔相似度的默认值并更改所有其他查询的行为。

有什么方法可以使用

function_score
实现与布尔相似性类似的行为或在运行时提供相似性?

java elasticsearch amazon-opensearch
1个回答
0
投票

感谢您的评论

我确信这是模糊的。您所需要的只是精确匹配总是比模糊匹配具有更高的分数

让我们修改您的查询以搜索不带模糊性和带模糊性的文本

GET /non-boolean_similarity/_search?filter_path=hits.hits
{
    "query": {
        "dis_max": {
            "queries": [
                {
                    "multi_match": {
                        "query": "FCC",
                        "type": "most_fields",
                        "fuzziness": 0,
                        "prefix_length": 0,
                        "operator": "AND",
                        "fields": [
                            "alias",
                            "name"
                        ],
                        "boost": 3
                    }
                },
                {
                    "multi_match": {
                        "query": "FCC",
                        "type": "most_fields",
                        "fuzziness": 1,
                        "prefix_length": 0,
                        "operator": "AND",
                        "fields": [
                            "alias",
                            "name"
                        ]
                    }
                }
            ]
        }
    }
}

我已经提升了查询而没有模糊性

回应

{
    "hits" : {
        "hits" : [
            {
                "_index" : "non-boolean_similarity",
                "_type" : "_doc",
                "_id" : "2",
                "_score" : 0.8630463,
                "_source" : {
                    "name" : "some data",
                    "alias" : [
                        "FCC"
                    ]
                }
            },
            {
                "_index" : "non-boolean_similarity",
                "_type" : "_doc",
                "_id" : "1",
                "_score" : 0.53506094,
                "_source" : {
                    "name" : "FAC"
                }
            }
        ]
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.