http - Elasticsearch 以更复杂的方式组合分数
问题描述
假设我们发出以下搜索请求:
GET my-index-000001/_search
{
query: {
multi_match: {
type: "most_fields",
query: "word1 word2",
fields: [
"name",
"name.prefix",
"name.suffix"
]
}
}
}
这样,Elasticsearch 索引中每个对象的返回分数等于以下每个字段的搜索分数之和:“name”、“name.prefix”、“name.suffix”。我怎么能得到以下分数,而不是得到所有这些字段的总和(searchResult(field) 表示从字段获得的分数,maximum() 返回最高分数): score = searchResult("name") + maximum(searchResult ("name.prefix"), searchResult("name.suffix")) ? 或者换句话说,我怎样才能得到一个字段的分数和其他两个字段的最大值的总和?
解决方案
您可以使用dis_max查询来获得最高分
如果返回的文档与多个查询子句匹配,则 dis_max 查询为该文档分配来自任何匹配子句的最高相关性分数,并为任何其他匹配的子查询加上一个平局增量。
{
"query": {
"bool": {
"should": [
{
"dis_max": {
"queries": [
{
"match": {
"name.prefix": "word1 word2"
}
},
{
"match": {
"name.suffix": "word1 word2"
}
}
],
"tie_breaker": 0.7
}
},
{
"match": {
"name.full_name": "word1 word2"
}
}
]
}
}
}
should 子句将给出 name.full_name 和 dis_max 查询的总和
如果您将使用 _search?explain=true 运行,您将获得有关如何计算分数的说明
"_explanation" : {
"value" : 1.3521059,
"description" : "sum of:",
"details" : [
{
"value" : 0.7767416,
"description" : "max plus 0.7 times others of:",
"details" : [
{
"value" : 0.2876821,
"description" : "sum of:",
"details" :[....]
},
{......}
]
},
{
"value" : 0.5753642,
"description" : "sum of:",
"details" : [
.........
]
}
]
}
推荐阅读
- javascript - 如何在ajax调用中使用GET请求显示服务器响应的页面
- javascript - 如何改进用于生产的节点 js 代码并在文件之间正确拆分?
- java - urlConnection.getOutputStream 卡住
- java - JavaFX 11:将图形添加到右侧的 TitledPane
- php - PHP邮件程序不起作用
- c# - 有没有办法改变 Parallel.Foreach 交错其操作的数组的方式?
- angular - Angular 5 :-来自 api 的模板
- ios - Xcode 10:添加简单约束时出现歧义约束错误
- python-3.x - 在 python 中显示 Latex - matplotlib
- image - 如何随机排列文件夹中的所有图像文件?