elasticsearch - Elasticsearch 应该有不同的分数
问题描述
我通过过滤和使用布尔查询来应用分数来检索文档。例如:
{
"query": {
"bool": {
"should": [
{
"term": {
"color": "Yellow"
}
},
{
"term": {
"color": "Red"
}
},
{
"term": {
"color": "Blue"
}
}
],
"minimum_should_match": 1
}
}
}
如果数据只有“黄色”,它会给我“1.5”的分数,但如果数据只有“红色”,它会给我“1.4”的分数。我希望分数是一样的。每个数据只有 1 个匹配项,为什么分数不同?应该查询中有什么可以忽略术语的顺序吗?当我只有 1 场比赛时,“黄色”的比赛总是会获得高分......
更新:问题不是应该数组中的术语顺序,而是“包含该术语的文档数量”
解决方案
如果评分对您不重要,您可以将filter
子句与子句一起使用bool/should
过滤上下文避免了评分部分,是一个正常的是/否查询。因此,匹配文档的分数将始终为 0.0
{
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"term": {
"color.keyword": "Yellow"
}
},
{
"term": {
"color.keyword": "Black"
}
},
{
"term": {
"color.keyword": "Purple"
}
}
],
"minimum_should_match": 1
}
}
}
}
}
匹配文档的分数取决于几个因素,例如字段长度、术语频率、文档总数等。
GET /_search?explain=true
推荐阅读
- php - 如何从控制器中的 foreach 获取视图中的所有记录?
- timestamp - RethinkDB 时间戳过滤问题
- python-3.x - Python Tkinter 检查框架是否存在
- c# - 如何使用日期时间选择器过滤数据?
- javascript - Chrome中的翻转动画从非活动侧显示一半元素
- php - HTTPS 的重定向站点
- sql - 具有多个条件的 Teradata SQL CASE 语句
- automationanywhere - 在同一台服务器上的不同会话中运行机器人
- css - 您可以使用 ::slotted() 伪选择器来定位特定的命名插槽吗
- swift - 在 Google 地图上为 KML 图层添加颜色