简体   繁体   English

elasticsearch 结果有错误评分

[英]elasticsearch results have wrong scoring

I have problem with elasticsearch scoring in my index.我的索引中的 elasticsearch 得分有问题。 First I show the codes then I explain my problem.首先我显示代码然后我解释我的问题。

my index setting:我的索引设置:

{
  "crucial": {
    "aliases": {},
    "mappings": {
      "properties": {
        "brand_id": {
          "type": "long"
        },
        "brand_name": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "category_name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "id": {
          "type": "long"
        },
        "name": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    },
    "settings": {
      "index": {
        "max_ngram_diff": "10",
        "routing": {
          "allocation": {
            "include": {
              "_tier_preference": "data_content"
            }
          }
        },
        "number_of_shards": "1",
        "provided_name": "crucial",
        "creation_date": "1659346772973",
        "analysis": {
          "analyzer": {
            "autocomplete": {
              "filter": [
                "lowercase"
              ],
              "tokenizer": "autocomplete"
            },
            "autocomplete_search": {
              "filter": [
                "lowercase"
              ],
              "tokenizer": "standard"
            }
          },
          "tokenizer": {
            "autocomplete": {
              "type": "ngram",
              "min_gram": "2",
              "max_gram": "12"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "wo245x3nQaCw3s9e0LSrlA",
        "version": {
          "created": "8030299"
        }
      }
    }
  }
}

search query:搜索查询:

GET crucial/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "brand_name": "asus"
          }
        },
        {
          "match": {
            "name": "asus x452l"
          }
        }
      ]
    }
  },
  "aggs": {
    "auto_complete": {
      "terms": {
        "field": "brand_id",
        "order": {
          "_count": "desc"
        }
      }
    }
  }, "size": 20
}

output: output:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 319,
      "relation": "eq"
    },
    "max_score": 13.513464,
    "hits": [
      {
        "_index": "crucial",
        "_id": "63400",
        "_score": 13.513464,
        "_source": {
          "id": 63400,
          "name": "asus x409",
          "brand_name": "asus",
          "brand_id": 12,
          "category_name": "x400 series"
        }
      },{
        "_index": "crucial",
        "_id": "63412",
        "_score": 13.279591,
        "_source": {
          "id": 63412,
          "name": "asus x452e",
          "brand_name": "asus",
          "brand_id": 12,
          "category_name": "x400 series"
        }
      }
    ]
  },
  "aggregations": {
    "auto_complete": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 12,
          "doc_count": 297
        },
        {
          "key": 40,
          "doc_count": 22
        }
      ]
    }
  }
}

As you can see the search query is "asus x452l" and I expected "asus x452e" to have maximum score but it's not?如您所见,搜索查询是“asus x452l”,我希望“asus x452e”获得最高分,但事实并非如此? what is the problem with scoring and how can I fix this?评分有什么问题,我该如何解决?

The problem was in difference of autocomplete_search tokenizer and autocomplete tokenizer.问题在于autocomplete_search分词器和autocomplete分词器的不同。

"analyzer": {
        "autocomplete": {
          "filter": [
            "lowercase"
          ],
          "tokenizer": "autocomplete"
        },
        "autocomplete_search": {
          "filter": [
            "lowercase"
          ],
          "tokenizer": "standard"
        }
      }

Changing "search_analyzer": "autocomplete_search" to "search_analyzer": "autocomplete" fixed my problem."search_analyzer": "autocomplete_search"更改为"search_analyzer": "autocomplete"解决了我的问题。

  "brand_name": {
      "type": "text",
      "analyzer": "autocomplete",
      "search_analyzer": "autocomplete_search"
  },"name": {
      "type": "text",
      "analyzer": "autocomplete",
      "search_analyzer": "autocomplete_search"
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM