![](/img/trans.png)
[英]Elasticsearch Edge NGram tokenizer higher score when word begins with n-gram
[英]Higher score for first word in ElasticSearch
現在,當我說“雞蛋”時,我的搜索結果給了我不想要的結果。 我得到以下信息:
_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”,則應該首先顯示以該單詞開頭的結果。 任何想法如何實現這一點?
感謝https://discuss.elastic.co上的人弄清楚了。
"query": {
"bool": {
"must": { "match": { "_all": request_text }},
"should":
{
"span_first" : {
"match" : {
"span_term" : { "_all" : request_text }
},
"end" : 1
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.