Java API client - single metric aggregation zero or null deserializer

I am using elasticsearch-java api client (8.10.3) and facing a small issue and I hope someone has already encountered this issue before.

I am trying to perform a min aggregation on documents that may not contain the field I try to aggregate. In case that all the documents that match my query don't contain the field I try to aggregate, the "value": null is being deserializing to 0 via the JsonpDeserializer.doubleOrNullDeserializer(0) which is defined inside the setupSingleMetricAggregateBaseDeserializer SingleMetricAggregateBase class

In my opinion, this approach may lead to confusion in our product and I am searching a way to avoid this deserialization but I couldn't find so far. It's ok to return null in that case and I would prefer to achieve this.

any ideas? :slight_smile:

I tried to add also value count aggregation in order to determine if there are values in the field I try to aggregate and it worked but it is a little weird in my opinion.

Hello!
The Java client defaults to zero when deserializing aggregation results because of a design choice that was made in order to avoid boxing numbers, which could increase memory usage substantially.
Using the document count provided in the response to make sure that the 0 returned is a "real zero" is a valid approach, and in general since modifying this behaviour would be a breaking change we would prefer to keep it as is for now.

1 Like

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