在ElasticSearch中合并多个查询得分

mlnl4t2r  于 2023-02-03  发布在  ElasticSearch
关注(0)|答案(2)|浏览(159)

我使用ElasticSearch搜索工作机会。
我希望能够直接搜索报价的信息,以获得第一个分数,然后与本地化的报价,最终与合同类型的分数细化。
目前,我只是通过修改权重在相同的函数评分内处理3种类型的请求。
但我希望能够按时间顺序,即按以下顺序:文本搜索〉本地化搜索〉合同类型搜索
这就是我当前正在执行的查询的示例

{
"query": {
    "bool": {
        "filter": [
            {
                "bool": {
                    "should": [
                        {
                            "nested": {
                                "path": "contract_types",
                                "query": {
                                    "term": {
                                        "contract_types.id": 3
                                    }
                                }
                            }
                        },
                        {
                            "nested": {
                                "path": "contract_types",
                                "query": {
                                    "term": {
                                        "contract_types.id": 2
                                    }
                                }
                            }
                        }
                    ],
                    "must": [
                        {
                            "nested": {
                                "path": "display_on",
                                "query": {
                                    "match": {
                                        "display_on.name": "Yupeek"
                                    }
                                }
                            }
                        },
                        {
                            "geo_distance": {
                                "distance": "60km",
                                "location": {
                                    "lat": 43.517214,
                                    "lon": 1.4980801
                                }
                            }
                        }
                    ],
                    "must_not": [
                        {
                            "term": {
                                "id": 273822
                            }
                        }
                    ],
                    "minimum_should_match": 1
                }
            }
        ],
        "must": [
            {
                "function_score": {
                    "query": {
                        "bool": {
                            "should": [
                                {
                                    "simple_query_string": {
                                        "query": "Automaticien Ingénieur Toulouse",
                                        "fields": [
                                            "title.stop^10",
                                            "description.stop^2"
                                        ],
                                        "boost": 5
                                    }
                                },
                                {
                                    "simple_query_string": {
                                        "query": "Industrie",
                                        "fields": [
                                            "sector.stop^1",
                                            "description.stop^2"
                                        ],
                                        "boost": 1
                                    }
                                },
                                {
                                    "simple_query_string": {
                                        "query": "Agroalimentaire",
                                        "fields": [
                                            "job.stop^5",
                                            "description.stop^2"
                                        ],
                                        "boost": 3
                                    }
                                },
                                {
                                    "distance_feature": {
                                        "field": "location",
                                        "pivot": "25km",
                                        "origin": {
                                            "lat": 43.517214,
                                            "lon": 1.4980801
                                        },
                                        "boost": 5
                                    }
                                },
                                {
                                    "nested": {
                                        "path": "contract_types",
                                        "query": {
                                            "match": {
                                                "contract_types.id": {
                                                    "query": 3,
                                                    "boost": 3
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "nested": {
                                        "path": "contract_types",
                                        "query": {
                                            "match": {
                                                "contract_types.id": {
                                                    "query": 2,
                                                    "boost": 1
                                                }
                                            }
                                        }
                                    }
                                }
                            ],
                            "minimum_should_match": 3
                        }
                    }
                }
            }
        ]
    }
},
"from": 0,
"size": 30,
"explain": true,
"highlight": {
    "fields": {
        "title.stop": {
            "number_of_fragments": 5,
            "fragment_size": 1000
        },
        "sector.stop": {
            "number_of_fragments": 5,
            "fragment_size": 1000
        },
        "job.stop": {
            "number_of_fragments": 5,
            "fragment_size": 1000
        },
        "company.stop": {
            "number_of_fragments": 5,
            "fragment_size": 1000
        },
        "description.stop": {
            "number_of_fragments": 5,
            "fragment_size": 1000
        }
    }
}

}

4uqofj5v

4uqofj5v1#

您是否考虑过对每个查询给予不同的提升;也就是说,给重要的人更多的激励,给最不重要的人更少的激励。这样,得分就能照顾到你正在努力做的事情。
建议阅读-https://www.elastic.co/blog/how-to-improve-elasticsearch-search-relevance-with-boolean-queries

scyqe7ek

scyqe7ek2#

下面是一个ElasticSearch查询,我首先使用关键字来限制结果,然后使用脚本评分来重新评分文档(在本例中使用向量评分)

**GET (your index)/_search
{"_source": ["abstract","title"], 
  "size": 10,
  "query": {
    "script_score": {
        "query": {
    "query_string": {
      "query": "Redox AND Battery OR (Fuel Cell)",
      "default_field": "*"
    }
  },
      "script": {
        "source": "cosineSimilarity(params.query_value, doc[params.field])",
        "params": {
          "field": "vector",
          "query_value": [(your vector here)]}}}}}**

这种方法是相当有限的,虽然,只使用向量相似性。我很想听听你是否找到了一个更好的解决这个问题的方法

相关问题