【发布时间】:2015-08-27 15:13:22
【问题描述】:
当我在一个字段上搜索时,评分似乎没有考虑字段的长度(即文本较长的文档的评分与较短的文档相同,并且由于某种原因放在前面)。不知道我做错了什么。
字段的索引如下:
"name": {
"type": "string",
"analyzer": "autocomplete"
},
"_alias": {
"type": "string",
"analyzer": "autocomplete"
}
分析器:
"autocomplete": {
"char_filter": [
"special_character_mapping"
],
"filter": [
"lowercase",
"autocomplete_filter"
],
"tokenizer": "whitespace"
}
过滤器:
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
查询 1:
{
"query": {
"multi_match": {
"query": "brown fo",
"type": "most_fields",
"fields": [
"name",
"_alias"
],
"use_dis_max": true,
"tie_breaker": 1,
"minimum_should_match": "100%",
"analyzer": "standard"
}
}
}
这会返回很多类似的文档:
- 棕狐
- 棕狐
- 布朗尼为
最后在第 10 位左右:
- 棕狐
更何况还有一个文档(棕狐树)在第 15 位左右还有一个别名“Brown”没有考虑在内。
查询 2:
{
"query": {
"multi_match": {
"query": "brown fo",
"type": "cross_fields",
"fields": [
"name",
"_alias"
],
"use_dis_max": true,
"tie_breaker": 1,
"minimum_should_match": "100%",
"analyzer": "standard"
}
}
}
这会返回更好的结果:
- 棕狐树
- 棕狐
- 棕狐
2nd 和 3d 文档的评分始终相同。第一个有一个别名“Brown”,理所当然地在前面。
我尝试了各种 multi_match 类型和 query_string 但结果都是一样的。
如何将文本较短的文档(lucene应该自己做?)放在其余文档的前面?
【问题讨论】:
-
我有两点:1)为什么您在查询中指定
standard分析器,即使您已将autocomplete指定为您搜索的字段的搜索和索引分析器,以及 2)您在您的autocomplete分析器中缺少"type": "custom"。 -
标准应该用于搜索时间(elastic.co/guide/en/elasticsearch/guide/current/…)。虽然不知道类型,但它是如何在代码中丢失的。如果你不输入 type: "custom" 是什么意思?
-
您是否尝试过添加
?explain=true来查看得分是如何计算的?
标签: elasticsearch