i need get searched result sorted by _score and date field i use below query in php elasticseach and get result true by _score , but i need sort data with _score and date field
Array([index] => my_index [from] => 0 [size] => 20 [body] => Array ( [query] => Array ( [bool] => Array ( [must] => Array ( [0] => Array ( [multi_match] => Array ( [query] => i need find it [operator] => or [fields] => Array ( [0] => src ) [lenient] => 1 ) ) ) ) ) ) [sort] => Array([0] => _score:desc))
CodePudding user response:
You can add one more field in sort array. Below is example of Elasticsearch query:
{
"sort": [
{
"_score": "desc"
},
{
"date": {
"order": "asc",
"format": "strict_date_optional_time_nanos"
}
}
],
"query": {
"term": {
"user": "kimchy"
}
}
}
PHP Example
'sort' => array(
array("_score" => "desc"),
array("date" => "asc")
)