# Kibana - Incorrect Count # with Bucket Aggregation "Terms"

**URL:** <https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895>\
**Category:** Kibana\
**Created:** [July 30, 2019, 12:39pm UTC](https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895 "2019-07-30T12:39:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RattleZ](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RattleZ](https://discuss.elastic.co/u/RattleZ)\
**Post date:** [July 30, 2019, 12:39pm UTC](https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895/1 "2019-07-30T12:39:18Z")

</div>

Hi,

I'd like to create a Visualisation for our Sales team, to easily show what the top 3 sold items are.

I have come across a strange behaviour when using a simple Visualisation where I would like to count the top 3 Terms from all the documents in my index. Doesn't matter which Visualisation I choose, its always the same result.

My index has 999 documents, so I leave the Y-Axis aggregation as: "Count"  
-\> The result shows correctly 999 results

I then create a Bucket with an Aggregation of "Terms" and pick the Field "Listing Title" and select "Descending, Size: 3"  
-\> The result shows the 3 Items but the Aggregated number is incorrect. Its shows 12 instead of 14.  
I checked the source CSV and the Top sold items appears indeed 14 times. There are no typos/whitespaces which could mess with the Visualisation.

When I change the Bucket settings from: "Descending, Size: 3" to: "Descending, Size: 9999", I get the correct Amount of 14 displayed. But then I also get all the other Items we are not interested in, displayed.

Am I missing something here or is this an intended behaviour? I have also played around wth other Bucket types/Aggregations, but I never get the result that I'd like. Any ideas what I might be doing wrong here?

 ![22](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4ad421842c5e4a4f2b9b4b887a98a4a37c7bdab8.png) ![44](https://us1.discourse-cdn.com/elastic/original/3X/9/d/9d4f47586d0e50666e147db348525ba472d3f560.png)

---

<div class="post-metadata">

**Author:** ![Aaron\_Caldwell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron_caldwell/32/45755_2.png) [@Aaron\_Caldwell](https://discuss.elastic.co/u/Aaron_Caldwell)\
**Post date:** [July 30, 2019, 4:00pm UTC](https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895/2 "2019-07-30T16:00:23Z")

</div>

Hello,

This sounds related to the terms returned per shard. Might be worth reading through this discuss issue which includes some helpful links on how to account for and resolve issues related to smaller queries and their interplay with shard size:

> [@Confusion Regarding Unstable Bucket-ing in Kibana Visualizations](https://discuss.elastic.co/t/confusion-regarding-unstable-bucket-ing-in-kibana-visualizations/117237):
>
> Hello everyone, I have been currently exploring Kibana visualizations of some test data, specifically horizontal bar charts. I had been attempting to bucket the x-axis by aggregation of terms when I was surprised to notice that, when using count as the ordering metric, manipulating the depth of the descending ordering caused the actual values of the counts results to change! Specifically, I was looking at the top 10 fields in descending order, and their ordering was different depending on whe…

Regards,  
Aaron

---

<div class="post-metadata">

**Author:** ![RattleZ](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RattleZ](https://discuss.elastic.co/u/RattleZ)\
**Post date:** [July 31, 2019, 12:28am UTC](https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895/3 "2019-07-31T00:28:03Z")

</div>

Excellent. That has helped pointing me in the right direction.  
I've created a default Index template with a default shard size and replica of 1 and now I am getting the correct results!

Thanks for that, much appreciated!

---

<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:** [August 28, 2019, 12:28am UTC](https://discuss.elastic.co/t/kibana-incorrect-count-with-bucket-aggregation-terms/192895/4 "2019-08-28T00:28:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
