在弹性搜索中按分数和日期排序
sort by score and date in elasticsearch
我需要得到按分数和日期字段排序的搜索结果
我在 php elasticseach 中使用以下查询并通过 _score 获得结果 true,但我需要使用 _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))
您可以在排序数组中添加一个字段。下面是 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")
)
我需要得到按分数和日期字段排序的搜索结果 我在 php elasticseach 中使用以下查询并通过 _score 获得结果 true,但我需要使用 _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))
您可以在排序数组中添加一个字段。下面是 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")
)