You can achieve that using _msearch
API.
Below is a sample query as how you can apply this:
POST myalias/_msearch
{"index" : "myindex_news_sports"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 1}
{"index" : "myindex_news_economics"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 1}
Basically, _msearch
allows you to search multiple requests using the same API. There are two different queries, where you can specify size
for two different indexes.
Note that the results would appear in separate groups of JSONs(two results, one for each query).
Sample Response:
{
"took" : 4,
"responses" : [
{ <---- Response for Index 1
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex_news_sports",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
},
{
"_index" : "myindex_news_sports",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
}
]
},
"status" : 200
},
{ <---- Response for Index 2
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex_news_economics",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
},
{
"_index" : "myindex_news_economics",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
}
]
},
"status" : 200
}
]
}
Not sure if this would be ideal for you, I just hope this helps.