我需要按 _score 和日期欄位排序的搜索結果,我在 php elasticseach 中使用下面的查詢并通過 _score 獲得結果,但我需要使用 _score 和日期欄位對資料進行排序
Array([index] => my_index [from] => 0 [size] => 20 [body] => Array ( [query] => Array ( [bool] => Array ( [must] => Array ( [0 ] => Array ( [multi_match] => Array ( [query] => 我需要找到它 [operator] => or [fields] => Array ( [0] => src ) [lenient] => 1 ) ) ) ) ) [排序] => 陣列([0] => _score:desc))
uj5u.com熱心網友回復:
您可以在排序陣列中再添加一個欄位。下面是 Elasticsearch 查詢的示例:
{
"sort": [
{
"_score": "desc"
},
{
"date": {
"order": "asc",
"format": "strict_date_optional_time_nanos"
}
}
],
"query": {
"term": {
"user": "kimchy"
}
}
}
PHP 示例
'sort' => array(
array("_score" => "desc"),
array("date" => "asc")
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/477669.html
上一篇:關于彈性搜索中的別名實作
