【问题标题】:Elastic Search text search not scoring more for exact matchElastic Search 文本搜索在完全匹配方面得分不高
【发布时间】:2026-01-04 04:10:02
【问题描述】:

我在 ES 索引中创建了以下映射:

{
  "field_to_search": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  }
}

并使用以下查询获取数据:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "field_to_search": {
              "query": "is this test?",
              "boost": 10,
              "fuzziness": "2",
              "prefix_length": 2
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "size": 20
}

得到结果:

{
  "_index": "test",
  "_id": "2551",
  "_score": 70.02259,
  "_source": {
    "id": "2551",
    "field_to_search": "is this test value?",
  }
}, 
{
  "_index": "test",
  "_id": "2545",
  "_score":  61.861847,
  "_source": {
    "id": "2545",
    "field_to_search": "is this test?",
  }
},
{
  "_index": "test",
  "_id": "2355",
  "_score":  50.987878,
  "_source": {
    "id": "2355",
    "field_to_search": "is this test performance value?",
  }
}

预期:这是测试吗?文档在上面

这里我没有得到完全匹配。精确匹配的分数低于模糊匹配。有人可以在这里帮忙吗?

我也尝试过使用 min boost 进行模糊查询,但没有奏效。

【问题讨论】:

  • 根据field_to_search的映射数据类型为object,而结果显示field_to_search的类型为text。这是不可能的。你确定映射正确吗?
  • 是的。我还为该字段添加了如下映射:“field_to_Search”:{“type”:“text”,“fields”:{“keyword”:{“type”:“keyword”,“ignore_above”:256}} },
  • 好的,我更新了相关映射。
  • This 回答可能会有所帮助。
  • 您作为结果添加的所有文档都具有相同的 ID。这些是执行查询三次的输出吗?你能添加你索引的文档,你用来索引它们的完整查询 dsl 吗?

标签: elasticsearch elasticsearch-5


【解决方案1】:

您是否在每次映射更新后重新索引数据?

&explain=true 将提供更多得分见解。

【讨论】:

  • 是的,我在每次映射更新后都重新索引了我的数据。我也尝试过 explain=true 但对我不起作用。我正在使用 ES 5.4.2。版本可能会导致问题吗?
最近更新 更多