I've been working on a BI system with ES 0.90 and we needed count "users" which have certain attributes, for instance let's say gender and star sign. A user is a parent-level document and the attributes are child documents.
Fro the sample above, we were doing so by creating a query for each combination of male / female and the star signs and querying individually, as one can imagine, this was slow, but the results are exactly what we want. We could run this in roughly 2 minutes.
We considered using the msearch query to get these results in a single query and we ended up with something similar to this: https://gist.github.com/chaos-generator/9133118
The sample above runs in 40 seconds give or take.
And along came elastic search 1.0.0 and now we have aggregations, so we simplified our query to this: https://gist.github.com/chaos-generator/9133139
This runs lightning fast and we get the results in 200ms on average, which is ideal for us, BUT we get the total number of documents with the attributes, rather than the count on the parent documents.
Our problem, as you can see in the msearch gist, is that we have a parent level document and child documents, which would only be updated if another document with the exact same attributes came in, this means that a parent level user document can have three child documents that will have gender and star sign, but I only want to count the parent document, rather than each individual child document.
As we don't know in advance the attributes our users will be searching, we cannot use a script in index time to help us do this aggregation. We tried to use a script in search time like this: https://gist.github.com/chaos-generator/9133321 , but it didn't work as we wanted too:
I've tried the bucket filter, but had problems with parent/child relationships.
I've modified the multi-search query to use type = count, but the performance didn't change much, it took about 40 seconds to return the results. It was almost 20% faster indeed, but it is not the performance we want yet.