To search in nested facets and returning the count of root documents

Hi,
I have a user document which has nested tags stored in it. Tags can be of
varied types - college, company, location, etc. I want to construct a query
that is composed of multiple facet queries each for different types of tags
which I mentioned above.
My individual facet queries are different in each case. So, I included
those differences in facet query.
But when I query nested facets, it returns the count of the nested
documents. I want the count of root documents.
Here is my user mapping
{
"user" : {
"properties" : {
"tags" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "string",
"index" : "not_analyzed",
"store" : "yes"
},
"current" : {
"type" : "boolean"
},
"type" : {
"type" : "string"
},
"value" : {
"type" : "multi_field",
"fields" : {
"value" : {
"type" : "string",
"analyzer" : "name_analyzer"
},
"value_untouched" : {
"type" : "string",
"index" : "not_analyzed",
"include_in_all" : false
}
}
}
}
}
}
}
}
This is my sample document:
{
"tags": [
{
"type": "college",
"value": "Velammal Institute of Technology",
"id": "f96807dcac0f218f41ff67ecb5a4881ee4f93a3f"
},
{
"type": "company",
"value": "TCS-Tata consultancy services",
"id": "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
},
{
"type": "company",
"value": "TCS-Tata consultancy services"
"id" : "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
"current" : true
}
]
}
tag_ids are generated manually through a combination of its type and value.
The current field in company determines whether it is a current company or
not.
I want to get the company facets of all the documents. So, this is my query:
{
"query": {
"filtered": {
"query": {
"match_all": {

    }
  },
}

},
"facets": {
"company": {
"terms": {
"field": "tags.value.value_untouched",
"size": 0
},
"nested": "tags",
"facet_filter": {
"term": {
"tags.type": "company"
}
}
}
}
}
This query returns me the count of nested facets but I want the counts of
matching root documents. How do I do that?

Thanks,
Aash

--
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.