Elasticsearch 查询 returns 奇怪的排序(基于分数)结果
Elasticsearch query returns strange sorted (score based) result
我正在使用 Elasticsearch v5.3.2
我有以下映射:
{
"mappings":{
"info":{
"_all":{
"enabled": false
},
"properties":{
"info":{
"properties":{
"email":{
"doc_values":"false",
"fields":{
"ngram":{
"analyzer":"custom_nGram_analyzer",
"type":"text"
}
},
"type":"keyword"
}
}
}
}
}
},
"settings":{
"analysis":{
"analyzer":{
"custom_nGram_analyzer":{
"filter":[
"lowercase",
"asciifolding",
"custom_nGram_filter"
],
"tokenizer":"whitespace",
"type":"custom"
}
},
"filter":{
"custom_nGram_filter":{
"max_gram":16,
"min_gram":3,
"type":"ngram"
}
}
}
}
}
当我执行以下查询时,我在文档分数方面看到了非常奇怪的结果:
GET /info_2017_08/info/_search
{
"query": {
"multi_match": {
"query": "hotmail",
"fields": [
"info.email.ngram"
]
}
}
}
它带来了以下结果:
"hits": {
"total": 3,
"max_score": 1.3834574,
"hits": [
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQnCjzNcTF2GMY730",
"_score": 1.3834574,
"_source": {
"info": {
"email": "pv53p8vg@gmail.com"
}
}
},
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQm93zNcTF2GMY73x",
"_score": 0.3967861,
"_source": {
"info": {
"email": "-vb6sbw54@hotmail.com"
}
}
},
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQmYbzNcTF2GMY73P",
"_score": 0.36409757,
"_source": {
"info": {
"email": "985pu4c.r02a@gmail.com"
}
}
}
]
}
现在关注分数。如果第一个结果是...@gmail.com,第二个结果是...@hotmail.com,如果我搜索了 "hotmail"?
第二个应该匹配ngrams "mail"和"hotmail"的查询,而第一个只会匹配ngram "mail"的查询,请问这样的原因是什么结果?
提前致谢。
Elasticsearch 使用 TF/IDF 统计数据独立计算每个分片上文档的分数。因此,如果您有两个包含下一个内容的分片:
- "info.email": "985pu4c.r02a@gmail.com"
- "info.email": "1085pu4c.r02a@gmail.com", "info.email": "-vb6sbw54@hotmail.com"
那么对于您的特定查询,来自第一个分片的单个文档的得分将高于来自第二个分片的任何文档。
您可以使用下一个 API 调用检查每个碎片的内容:GET index/_search?preference=_shards:0
我正在使用 Elasticsearch v5.3.2
我有以下映射:
{
"mappings":{
"info":{
"_all":{
"enabled": false
},
"properties":{
"info":{
"properties":{
"email":{
"doc_values":"false",
"fields":{
"ngram":{
"analyzer":"custom_nGram_analyzer",
"type":"text"
}
},
"type":"keyword"
}
}
}
}
}
},
"settings":{
"analysis":{
"analyzer":{
"custom_nGram_analyzer":{
"filter":[
"lowercase",
"asciifolding",
"custom_nGram_filter"
],
"tokenizer":"whitespace",
"type":"custom"
}
},
"filter":{
"custom_nGram_filter":{
"max_gram":16,
"min_gram":3,
"type":"ngram"
}
}
}
}
}
当我执行以下查询时,我在文档分数方面看到了非常奇怪的结果:
GET /info_2017_08/info/_search
{
"query": {
"multi_match": {
"query": "hotmail",
"fields": [
"info.email.ngram"
]
}
}
}
它带来了以下结果:
"hits": {
"total": 3,
"max_score": 1.3834574,
"hits": [
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQnCjzNcTF2GMY730",
"_score": 1.3834574,
"_source": {
"info": {
"email": "pv53p8vg@gmail.com"
}
}
},
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQm93zNcTF2GMY73x",
"_score": 0.3967861,
"_source": {
"info": {
"email": "-vb6sbw54@hotmail.com"
}
}
},
{
"_index": "info_2017_08",
"_type": "info",
"_id": "AV4uQmYbzNcTF2GMY73P",
"_score": 0.36409757,
"_source": {
"info": {
"email": "985pu4c.r02a@gmail.com"
}
}
}
]
}
现在关注分数。如果第一个结果是...@gmail.com,第二个结果是...@hotmail.com,如果我搜索了 "hotmail"?
第二个应该匹配ngrams "mail"和"hotmail"的查询,而第一个只会匹配ngram "mail"的查询,请问这样的原因是什么结果?
提前致谢。
Elasticsearch 使用 TF/IDF 统计数据独立计算每个分片上文档的分数。因此,如果您有两个包含下一个内容的分片:
- "info.email": "985pu4c.r02a@gmail.com"
- "info.email": "1085pu4c.r02a@gmail.com", "info.email": "-vb6sbw54@hotmail.com"
那么对于您的特定查询,来自第一个分片的单个文档的得分将高于来自第二个分片的任何文档。
您可以使用下一个 API 调用检查每个碎片的内容:GET index/_search?preference=_shards:0