【问题标题】:Higher score for first word in ElasticSearchElasticSearch 中第一个单词的得分更高
【发布时间】:2015-11-21 16:01:20
【问题描述】:

现在,当我搜索时,我的搜索会给出不需要的结果,比如“egg”。 我得到以下信息:

_score: 2.7645843
_source:
  django_id: "18003"
  text: "Bagels, egg"
  content_auto: "Bagels, egg"
  django_ct: "web.fooddes"
  allergies: []
  outdated: false
  id: "web.fooddes.18003"
_explanation:
  value: 2.7645843
  description: "weight(_all:egg in 516) [PerFieldSimilarity], result of:"
  details:
  - value: 2.7645843
    description: "fieldWeight in 516, product of:"
    details:
    - value: 1.4142135
      description: "tf(freq=2.0), with freq of:"
      details:
      - value: 2.0
        description: "termFreq=2.0"
    - value: 5.21295
      description: "idf(docFreq=26, maxDocs=1824)"
    - value: 0.375
      description: "fieldNorm(doc=516)"

作为第一个结果。

只有第五个甚至更远的通缉犯:

_score: 2.380459
_source:
  django_id: "01124"
  text: "Egg, white, raw, fresh"
  content_auto: "Egg, white, raw, fresh"
  django_ct: "web.fooddes"
  allergies: []
  outdated: false
  id: "web.fooddes.01124"
_explanation:
  value: 2.3804593
  description: "weight(_all:egg in 1489) [PerFieldSimilarity], result of:"
  details:
  - value: 2.3804593
    description: "score(doc=1489,freq=2.0), product of:"
    details:
    - value: 0.99999994
      description: "queryWeight, product of:"
      details:
      - value: 5.386365
        description: "idf(docFreq=22, maxDocs=1848)"
      - value: 0.18565395
        description: "queryNorm"
    - value: 2.3804595
      description: "fieldWeight in 1489, product of:"
      details:
      - value: 1.4142135
        description: "tf(freq=2.0), with freq of:"
        details:
        - value: 2.0
          description: "termFreq=2.0"
      - value: 5.386365
        description: "idf(docFreq=22, maxDocs=1848)"
      - value: 0.3125
        description: "fieldNorm(doc=1489)"

这是因为第一个结果中的单词较少,因此结果得分较高,因为“egg”在这种情况下更相关。

但是,我希望结果中遇到的第一个单词是最重要的。因此,如果我搜索单词“egg”,它应该首先显示以该单词开头的那些结果。有什么想法可以实现吗?

【问题讨论】:

    标签: search elasticsearch n-gram relevance


    【解决方案1】:

    感谢https://discuss.elastic.co 的人,我想通了。

      "query": {
          "bool": {
            "must": { "match": { "_all": request_text }},
            "should":
            {
              "span_first" : {
                "match" : {
                    "span_term" : { "_all" : request_text }
                },
                "end" : 1
              }
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 2019-04-13
      • 2014-10-24
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      • 2019-06-01
      • 2019-03-22
      相关资源
      最近更新 更多