I believe that you will need to use the /_msearch
API for this, to get back the different results.
Here's an example that I hope makes things clear, first some fake data:
PUT /i/d/1
{
"shop_name" : "Armani",
"country" : "italy",
"city": "milan",
"relevance" : 10
}
PUT /i/d/2
{
"shop_name" : "Shop2",
"country" : "italy",
"city": "milan",
"relevance" : 5
}
PUT /i/d/3
{
"shop_name" : "Store3",
"country" : "italy",
"city": "campione",
"relevance" : 12
}
PUT /i/d/3
{
"shop_name" : "Store4",
"country" : "italy",
"city": "campione",
"relevance" : 3
}
PUT /i/d/4
{
"shop_name" : "Store5",
"country" : "switzerland",
"city": "lugano",
"relevance" : 10
}
PUT /i/d/5
{
"shop_name" : "Store6",
"country" : "switzerland",
"city": "lugano",
"relevance" : 18
}
The query you'll execute then:
POST /i/_msearch
{}
{"query": {"match": {"city": "milan"}}, "size": 10, "sort": {"relevance": {"order": "desc"}}}
{}
{"query": {"match": {"country": "italy"}}, "size": 5, "sort": {"relevance": {"order": "desc"}}}
{}
{"query": {"match_all": {}}, "size": 5, "sort": {"relevance": {"order": "desc"}}}
And then, the results you get back from the /_msearch
, which I believe is what you are looking for:
{
"responses" : [
{
"took" : 81,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [
{
"_index" : "i",
"_type" : "d",
"_id" : "1",
"_score" : null,
"_source" : {
"shop_name" : "Armani",
"country" : "italy",
"city" : "milan",
"relevance" : 10
},
"sort" : [
10
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "2",
"_score" : null,
"_source" : {
"shop_name" : "Shop2",
"country" : "italy",
"city" : "milan",
"relevance" : 5
},
"sort" : [
5
]
}
]
},
"status" : 200
},
{
"took" : 76,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : null,
"hits" : [
{
"_index" : "i",
"_type" : "d",
"_id" : "1",
"_score" : null,
"_source" : {
"shop_name" : "Armani",
"country" : "italy",
"city" : "milan",
"relevance" : 10
},
"sort" : [
10
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "2",
"_score" : null,
"_source" : {
"shop_name" : "Shop2",
"country" : "italy",
"city" : "milan",
"relevance" : 5
},
"sort" : [
5
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "3",
"_score" : null,
"_source" : {
"shop_name" : "Store4",
"country" : "italy",
"city" : "campione",
"relevance" : 3
},
"sort" : [
3
]
}
]
},
"status" : 200
},
{
"took" : 74,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : null,
"hits" : [
{
"_index" : "i",
"_type" : "d",
"_id" : "5",
"_score" : null,
"_source" : {
"shop_name" : "Store6",
"country" : "switzerland",
"city" : "lugano",
"relevance" : 18
},
"sort" : [
18
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "4",
"_score" : null,
"_source" : {
"shop_name" : "Store5",
"country" : "switzerland",
"city" : "lugano",
"relevance" : 10
},
"sort" : [
10
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "1",
"_score" : null,
"_source" : {
"shop_name" : "Armani",
"country" : "italy",
"city" : "milan",
"relevance" : 10
},
"sort" : [
10
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "2",
"_score" : null,
"_source" : {
"shop_name" : "Shop2",
"country" : "italy",
"city" : "milan",
"relevance" : 5
},
"sort" : [
5
]
},
{
"_index" : "i",
"_type" : "d",
"_id" : "3",
"_score" : null,
"_source" : {
"shop_name" : "Store4",
"country" : "italy",
"city" : "campione",
"relevance" : 3
},
"sort" : [
3
]
}
]
},
"status" : 200
}
]
}
Hope that helps!