elasticsearch 在弹性模式中搜索靠近集数的movie_title

sqserrrh  于 2023-02-21  发布在  ElasticSearch
关注(0)|答案(1)|浏览(139)

当我搜索“it episode 2”时,我希望看到如下结果:“It eposition 2”、“It eposition 1”、...(其他电影中包含“it”)
但是我不想在我的搜索结果中看到其他电影的第二集(像《安娜贝尔》第二集那样在片名中没有“它”)。我怎么能做到呢?
这是我的Map
我有一个字段“title_fa”,其中我删除了停止词,如“插曲”或“2”
我有一个字段“title_fa.title_fa”,其中我只保留了停止词,如“插曲”或“2”

"title_fa": {
                "type": "text",
                "analyzer": "basic_title_fa",
                "boost": 40,
                "norms": "false",
                "fields": {
                    "title_fa": {
                        "type": "text",
                        "analyzer": "basic_title_fa_child",
                        "boost": 30,
                        "norms": "false",
                    },
                    "title_fa_raw": {
                        "type": "text",
                        "analyzer": "title_fa_keyword",
                        "boost": 80,
                        "norms": "false",
                    },
                    "with_ngram": {
                        "type": "text",
                        "analyzer": "ngram_fa",
                        "boost": 2
                    },
                    "with_back_ngram": {
                        "type": "text",
                        "analyzer": "ngram_back_fa",
                        "boost": 2
                    }
                }
            },

下面是我的查询搜索:

query = {
        "from": 0,
        "size": 300,
        "query": {
            "function_score": {
                "query": {
                    "multi_match": {
                            "query": keyword,
                            "type": "most_fields",
                            "fields": ["title_fa", "title_fa.title_fa"]
                        }
                },
                "functions": [
                    {
                        "weight": 2,
                        "filter": {
                            "multi_match": {
                                "query": keyword,
                                "fields": [
                                    "title_fa"
                                ]
                            }
                        }
                    },
                    {
                        "weight": 1,
                        "filter": {
                            "multi_match": {
                                "query": keyword,
                                "fields": [
                                    "title_fa.title_fa"
                                ]
                            }
                        }
                    }
                ]
            }
        }
    }

我想对title_fa的得分求和。只有当title_fa本身有得分时,title_fa才有得分

w1e3prcc

w1e3prcc1#

我想我有个解决办法。用查询重划。
这里我将使用“title_fa”进行搜索(标题中没有“episode”等常用词),然后我将根据其他字段(“title_fa.title_fa”中有“episode”等常用词)对结果进行重新排序。
下面是我的搜索查询:

"from": 0,
        "size": 300,
        "query": {
            "dis_max": {
                "queries": [
                    {
                        "multi_match": {
                            "query": keyword,
                            "type": "most_fields",
                            "fields": ["title_fa", "title_fa.title_fa_raw"]
                        }
                    }
                ]
            }
        },
        "rescore": {
            "window_size": 50,
            "query": {
                "rescore_query": {
                    "query_string": {
                        "query": keyword,
                        "fields": [
                            "title_fa.title_fa",
                        ]
                    }
                },
                "query_weight": 0.7,
                "rescore_query_weight": 1.2
            }
        }
    }

相关问题