# Wrong count for nested facets

**URL:** <https://discuss.elastic.co/t/wrong-count-for-nested-facets/13861>\
**Category:** Elasticsearch\
**Created:** [October 6, 2013, 6:11pm UTC](https://discuss.elastic.co/t/wrong-count-for-nested-facets/13861 "2013-10-06T18:11:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandr\_Lossenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aleksandr_lossenko/32/2068_2.png) [@Aleksandr\_Lossenko](https://discuss.elastic.co/u/Aleksandr_Lossenko)\
**Post date:** [October 6, 2013, 6:11pm UTC](https://discuss.elastic.co/t/wrong-count-for-nested-facets/13861/1 "2013-10-06T18:11:05Z")

</div>

I'm building search for products and variants. One product can have many  
nested variants. Example: 1 T-shirt can be in 2 variants, white for 50  
euros and green for 60 euros. It's still the same product and should be  
displayed once on the results page.

This is my mapping:

{"product" =\> { "properties" =\> {"vendor\_variants" =\> {"type" =\> "nested"}}}}

And this is the query that I'm doing:

"query" =\> {  
"filtered" =\> {  
"query" =\> {  
"match\_all" =\> {}  
},  
"filter" =\> {  
"bool" =\> {  
"must" =\> [  
{  
"terms" =\> {  
"categories" =\> [122]  
}  
}  
]  
}  
}  
}  
},  
"facets" =\> {  
"brand" =\> { "terms" =\> {"field" =\> "filter\_brand"} },  
"price\_range" =\> {  
"nested" =\> "vendor\_variants",  
"range" =\> { "field" =\> "price", "ranges" =\> [{"to" =\> 2000}, {"from" =\> 2000, "to" =\> 5000}]  
}  
}  
}

This query produces 172 results. But the facets for price ranges are  
completely wrong. For example it returns that for 20-50 euro range there  
are 422 results. I believe it's because it counts every single nested  
vendor\_variants document. But it's not what I need, I need it to count only  
the main product documents.

What is wrong with my query?

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:13am UTC](https://discuss.elastic.co/t/wrong-count-for-nested-facets/13861/2 "2017-07-06T02:13:29Z")

</div>


