elasticsearch,n-gram,relevance,Search,elasticsearch,N Gram,Relevance" /> elasticsearch,n-gram,relevance,Search,elasticsearch,N Gram,Relevance" />

ElasticSearch中第一个单词的分数更高

ElasticSearch中第一个单词的分数更高,search,elasticsearch,n-gram,relevance,Search,elasticsearch,N Gram,Relevance,现在,当我搜索时,我的搜索会给我不想要的结果,比如说“鸡蛋”。 我得到以下信息: _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:

现在,当我搜索时,我的搜索会给我不想要的结果,比如说“鸡蛋”。 我得到以下信息:

_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”,它首先应该显示以这个单词开头的结果。如何实现这一点有什么想法吗?

多亏了现场的人,我才想出了办法

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