I'm trying to build a query to aggregate on some fields in a nested
document, but instead of returning the count of the nested documents for
each aggregation, I'd like to know the number of root objects.
IE.,
I have a mapping like (from the docs):
"product" : {
"properties" : {
"resellers" : {
"type" : "nested"
"properties" : {
"name" : { "type" : "string" },
"price" : { "type" : "double" }
}
}
}
}
Now let's say I want to know how many products have each reseller name.
That's not straight forward as far as I can tell.
If I do an agg like:
"aggs": {
"resellers": {
"nested": {
"path": "resellers"
},
"aggs": {
"names": {
"terms": {
"field": "resellers.name"
...
I'll get back something like ( assuming that each product has many
resellers):
hits: 20,
aggregations: {
resellers: {
doc_count: 100,
names : {
buckets: [
{
key: 'name1'
doc_count: 50
},
{
key: 'name2',
doc_count: 50
}
]
}}}
So, its aggregating on the nested objects, ie there are 100 reseller nested
docs, and in them 50 have name1, 50 have name2.
What I'm interested in though is how many products have resellers with name
1 and name 2.
IE, it should say something like,
- 15 products have a reseller w/ name name1
- 10 products have a reseller w/ name name2
It looks like I can do this by putting a reverse nested aggregation below
my names agg, then do a value_count aggregation on the ID of the root
object. This seems kind of round about and I wonder if I'm missing an
easier way. Any suggestions would be appreciated !
Thanks,
-Kal
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1e895c15-accc-4638-b19c-ec1d263ca53b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.