# Terms Agg

**URL:** <https://discuss.elastic.co/t/terms-agg/170966>\
**Category:** Elasticsearch\
**Created:** [March 5, 2019, 6:03pm UTC](https://discuss.elastic.co/t/terms-agg/170966 "2019-03-05T18:03:24Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![aniaks](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aniaks](https://discuss.elastic.co/u/aniaks)\
**Post date:** [March 18, 2019, 3:44pm UTC](https://discuss.elastic.co/t/terms-agg/170966/21 "2019-03-18T15:44:36Z")

</div>

I set size and shard\_size to 4200 , but still i was not getting the intended results. So i set to less number 500 (both size and shard\_size) to see if that makes any difference. But still no difference.

sorry for the confusion.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 18, 2019, 3:47pm UTC](https://discuss.elastic.co/t/terms-agg/170966/22 "2019-03-18T15:47:09Z")

</div>

> [@aniaks](#):
>
> I set size and shard\_size to 4200 , but still i was not getting the intended results.

What did you get? Were there any failures reported in the response status or the JSON body?

---

<div class="post-metadata">

**Author:** ![aniaks](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aniaks](https://discuss.elastic.co/u/aniaks)\
**Post date:** [March 18, 2019, 3:48pm UTC](https://discuss.elastic.co/t/terms-agg/170966/23 "2019-03-18T15:48:33Z")

</div>

I was not getting empty buckets for the terms that do not have data. There was no error though.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 18, 2019, 3:55pm UTC](https://discuss.elastic.co/t/terms-agg/170966/24 "2019-03-18T15:55:34Z")

</div>

So you should have had exactly 4,200 term buckets under each date bucket. How many buckets did you get?  
Was this perhaps because some of the date buckets had exactly zero hits, in which case it didn't descend into the child terms aggregation?

---

<div class="post-metadata">

**Author:** ![aniaks](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aniaks](https://discuss.elastic.co/u/aniaks)\
**Post date:** [March 18, 2019, 4:05pm UTC](https://discuss.elastic.co/t/terms-agg/170966/25 "2019-03-18T16:05:12Z")

</div>

thats good point, i will check from that perspective.

---

<div class="post-metadata">

**Author:** ![aniaks](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aniaks](https://discuss.elastic.co/u/aniaks)\
**Post date:** [March 18, 2019, 4:06pm UTC](https://discuss.elastic.co/t/terms-agg/170966/26 "2019-03-18T16:06:39Z")

</div>

One more point to note - for the timeframe i am searching there are only 6 terms that would be returned. In my response some date has 4 and some date has 5 and some has 6.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 18, 2019, 4:16pm UTC](https://discuss.elastic.co/t/terms-agg/170966/27 "2019-03-18T16:16:37Z")

</div>

One possible factor is that [this optimisation](https://github.com/elastic/elasticsearch/pull/25658) avoids even running the query on some shards if they lie outside of the time range for the query.  
This would mean that terms that only exist on excluded shards would not appear in results.

If this is the reason behind the absence I don't suggest you trawl indices outside of your date range just to come up with the missing values - that would be very inefficient compared to an approach where your client can deduce the missing terms with some custom logic

---

<div class="post-metadata">

**Author:** ![aniaks](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@aniaks](https://discuss.elastic.co/u/aniaks)\
**Post date:** [March 18, 2019, 6:50pm UTC](https://discuss.elastic.co/t/terms-agg/170966/28 "2019-03-18T18:50:55Z")

</div>

If the terms outside the time range is not returned that would be fine. But in my case for a given time range - one timestamp has 5 buckets, one time stamp has 6 buckets and another has 4 buckets. I would expect all the time in the time range should have same number of buckets. Let me know if my understanding is right ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 18, 2019, 8:11pm UTC](https://discuss.elastic.co/t/terms-agg/170966/29 "2019-03-18T20:11:24Z")

</div>

> [@aniaks](#):
>
> I would expect all the time in the time range should have same number of buckets.

Not if the buckets are taken from different (time-based) indices. They each could have a different set of terms.

---

<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:** [April 15, 2019, 8:11pm UTC](https://discuss.elastic.co/t/terms-agg/170966/30 "2019-04-15T20:11:28Z")

</div>

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

[Previous page](https://discuss.elastic.co/t/terms-agg/170966.md?page=1)
