Help with grouping facet

Hello everyone,

I'm having a little trouble in building a query in my current elasticsearch
structure, and I wandered if its possible without changing the modeling.
My current structure is as follows:
I have a parent document type namely 'user', which has many child types
representing the many aspects of a users (the user documents themselves
contain no descriptive information whatsoever).
For example, I may have the child type 'computer' which contains the fields
'screencolor', 'screenwidth' and 'screenheight'. then I may have the child
type 'personal_info' which contains the fields 'name', 'age' and 'address'.
(By definition no different child types will have a field with the same
name, if that matters).
Another thing which is part of my design is the possibility of a single
user containing more than one child of the same type (e.g. one user can
have N computers).
The query I want to execute is as follows:
For every user which match a certain criteria, group the values of the
fields and return me the count of users grouped by the values of the fields.
An example would be:
Grouped by the values of 'screenwidth' and 'age', return me the count of
users.
It would be something like that:
{
"size": 0,
"query": {
"match_all": {}
},
"facets": {
"my_facet": {
"terms": {
"script_field": "source.age + '' +
_source.screenwidth",
"all_terms": True
}
}
}
}

This query would return me something like:
"facets": {
"my_facet": {
"type": "terms",
"missing": 0,
"total": 9,
"other": 0,
"terms": [
{
"term": "[24]
[1280]",
"count": 4
},
{
"term": "[32][800]",
"count": 2
},
{
"term": "[24]
[1920]",
"count": 1
},
{
"term": "[24][1440]",
"count": 1
},
{
"term": "[24]
[1366]",
"count": 1
}
]
}
}

The problem is, this only returns me the number of documents which match
the query, which is not the number of users, as there maybe more than 1
child document of the same type per user (by definition).
Is there some way to get what I want in a single query?
It should be clear that I cannot change this architecture, because other
parts of my system which depend on it, but I could create another index
just for this purpose.

Thanks a lot in advance,
Matheus Salvia

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.