Hello, I probably need to create a multi step multi index query and I am not sure if such a thing is supported or if it is the right approach at all.
Example Data:
2 indexes , 1 for orders, 1 for invoices
I made a simple query that scans the invoices index and counts the amount of referenced orders like so :
{
"aggs":{
"reference":{
"terms":{
"field":"References.DocType.SysName.keyword"
}
}
},
"query":{
"bool":{
"filter":[
{
"range":{
"MessageDate":{
"gte":"2015-05-24T00:00:00+03:00"
}
}
}
]
}
}
}
I am holding this information inside the invoice index so it is quite simple, by grouping by the docType of the references I can see how many references I got of type "order", also I needed to use a date in the query.
My problem is that later on I will also going to need to query for the actual orders data and not just the orders amount which located in a different index(orders).
But in order to determine which orders to return I first need to run something like the query above to determine which orders qualifies.
From the first query I got access to the order Ids with which I can find the actual orders in the orders index.
But I dont think it is very practical to make a second separate query by XXXXX amount of ids.
So I was wondering if it is possible to somehow make a merged query that finds all the order ids by the needed terms against the invoices index and then finds the actual orders from the orders index and retrieves those.