Hi,
I'm stuck with a concept of 2 sets of search results combined into 1 set (that would make paginating simple). My simplified mapping looks like this:
'properties' => [
'featured' => ['type' => 'boolean'],
'title' => ['type' => 'text', 'index' => true],
'location' => ['type' => 'geo_point'],
'language_iso1' => ['type' => 'keyword'],
]
I would like to retrieve all featured = true results within distance of 20km and have them first in my results array and then retrieve all the other results (featured and not featured) sorted by the distance (usually, it might be also sorted by relevance if user chooses so).
I have tried pinned query, which is great but when sorting the results I can only sort by the whole set (pinned and organic ones, which reshuffles the pinned ones as well). Is there any way to sort only organic results?
"from" => 0, "size" => 10,
'query' => [
"pinned" => [
"ids" => $array_of_ids,
"organic" => [
"bool" => [
"must" => [
["multi_match" => [
"query" => 'Alice',
"fields" => ["title"]
]],
["terms" => ["language_iso1" => ['en']]],
],
]
]
]
],
"sort" => [
["_geo_distance" => [
"location" => [
"lat" => 50,
"lon" => 50
],
"order" => "asc",
"unit" => "km",
"distance_type" => "arc",
]],
],
Or maybe is there any other way to achieve it? Thanks in advance for help.