我正在使用elasticsearch 7.9.0
。
該檔案的存盤方式為:
{
"學生"。{
"分數"。[
{
"子"。80
},
{
"子": 90
},
{
"子": 100
}
],
"total_marks": 270
}
}
如果學生缺席考試,我的檔案將是
。{
"學生"。{
"分數"。[
{
"子"。0
},
{
"子": 0
},
{
"子": 0
}
],
"total_marks": 0
}
}
現在,當搜索學生時,我的點擊率應該包含所有的學生,但缺席的學生應該在底部。
我不應該添加對總分的排序。
還有一些欄位需要匹配,排序應該根據elasticsearch的默認評分來完成。例如,優等生可能排在第一位,不及格的學生也可能排在第一位,但所有缺席的學生應該排在最后。
我們怎樣才能做到這一點呢?
我曾嘗試為totalmarks添加負數提升。它并沒有像預期的那樣作業。
請幫助我。謝謝你的幫助。
uj5u.com熱心網友回復:
提升查詢可用于降級某些檔案
正面 :- 我使用了 match_all 來回傳所有的檔案。
負面 :- 適用于從正面查詢中過濾出來的檔案子集,即負面檔案也必須在正面查詢中回傳。
查詢
{
"query": {
"boosting": {
"正面"。{
"match_all": {}
},
"負面": {
"范圍": {
"student.total_marks": {
"gte": 0,
"lte": 0
}
}
},
"negative_boost": 0.2,
"提升": 1
}
}
}
結果
"hits" :
[
{
"_index" : "index32",
"_type" : "_doc",
"_id" : "RTsT5HsBssOzZCY8olGD",
"_score" : 1.0,
"_source" : {
"學生" : {
"name" : "Guru",
"new_student" : true,
"total_marks" : 100
}
}
},
{
"_index" : "index32",
"_type" : "_doc",
"_id" : "RjsT5HsBssOzZCY8plFr",
"_score" : 1.0,
"_source" : {
"學生" : {
"name" : "Mayur",
"new_student" : false,
"total_marks" : 90
}
}
},
{
"_index" : "index32",
"_type" : "_doc",
"_id" : "STtN5HsBssOzZCY8olFq",
"_score" : 1.0,
"_source" : {
"學生" : {
"name" : "Abc",
"new_student" : true,
"total_marks" : 90
}
}
},
{
"_index" : "index32",
"_type" : "_doc",
"_id" : "RzsT5HsBssOzZCY8rVFz",
"_score" : 0.2,
"_source" : {
"學生" : {
"name" : "Darshan",
"new_student" : false,
"total_marks" : 0
}
}
},
{
"_index" : "index32",
"_type" : "_doc",
"_id" : "SDsT5HsBssOzZCY8uFEe",
"_score" : 0.2,
"_source" : {
"學生" : {
"name" : "Manu",
"new_student" : true,
"total_marks" : 0
}
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315183.html
標籤:
