# Strange behavior with date histogram aggregation in a field that is inside a nested object (Elasticsearch 7.10.0)

**URL:** <https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823>\
**Category:** Elasticsearch\
**Created:** [November 26, 2020, 8:18pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823 "2020-11-26T20:18:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 26, 2020, 8:18pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/1 "2020-11-26T20:18:03Z")

</div>

Hi!  
I'm in the middle of an upgrade process to the 7.10.0 Elasticsearch (changing the client from TransportClient to JavaRestHighLevelClient also) and I've noticed a strange behavior of [Date Histogram Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html) when it is inside a [Nested Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html).  
I have two Junits tests that cover, each, the scenarios inside a nested and not.

Without the nested, with a interval of `1d`, it works as expected:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/e/8e4ef34ed0fc9f8387ad8762e1f8298c945d661c.png)

But when I run the test that makes the date histogram (and its target field) inside a Nested, things get a little messy:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2ab4b4324c6d1cdee2f74c787e8cdf6e94c0bcf0.png)

What could possibly be the problem?

---

<div class="post-metadata">

**Author:** ![egalpin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egalpin/32/79772_2.png) [@egalpin](https://discuss.elastic.co/u/egalpin)\
**Post date:** [November 26, 2020, 8:43pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/2 "2020-11-26T20:43:23Z")

</div>

Though I have no impression that this would be at fault, it may be worth trying `fixed_interval` or `calendar_interval` as a sanity check since `interval` is deprecated. I can't imagine that would cause this though ¯\_(ツ)\_/¯

---

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 26, 2020, 9:25pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/3 "2020-11-26T21:25:17Z")

</div>

@egalpin, it makes no difference (I've tried with both, fixed and calendar interval).

---

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 27, 2020, 6:46pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/4 "2020-11-27T18:46:45Z")

</div>

Nobody? Should I fill a bug, instead?

---

<div class="post-metadata">

**Author:** ![egalpin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egalpin/32/79772_2.png) [@egalpin](https://discuss.elastic.co/u/egalpin)\
**Post date:** [November 27, 2020, 8:45pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/5 "2020-11-27T20:45:48Z")

</div>

> [@tberne](#):
>
> changing the client from TransportClient to JavaRestHighLevelClient also

Have you examined the generated query? I assumed so from your screenshots but just a sanity check to verify that the JSON query produced by the new client matches the old client's query. I personally don't know how the results could occur given the input interval, but very curious to know the answer too.

---

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 30, 2020, 1:39pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/6 "2020-11-30T13:39:44Z")

</div>

@egalpin, I suppose it has something to do with my data (although I have no idea why this is happening).  
I've checked the requests and they look ok. After that, I took the relevant requests (since the index creation to the search) and created a Dockerfile to simulate the problem. When I did that (with an empty container), the problem didn't occur.  
So, I can only imagine this is because some data my Elasticsearch has that an empty container wouldn't have.  
But, again, it makes no sense to me at all.

---

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 30, 2020, 5:33pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/7 "2020-11-30T17:33:52Z")

</div>

I finally managed to reproduce it. In 7.9.3 the problem isn't reproducible. Only in 7.10.0.

---

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [November 30, 2020, 6:11pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/8 "2020-11-30T18:11:54Z")

</div>

I've [filled a bug about this](https://github.com/elastic/elasticsearch/issues/65624).

---

<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:** [December 28, 2020, 6:12pm UTC](https://discuss.elastic.co/t/strange-behavior-with-date-histogram-aggregation-in-a-field-that-is-inside-a-nested-object-elasticsearch-7-10-0/256823/9 "2020-12-28T18:12:05Z")

</div>

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