Java API enforces specifying both min and max in extended bounds unlike RHLC


Edit: tested on dockerized Elasticsearch 7.17.7, 7.17.9, client version is 7.17.9

During migration to Java API client (from rest high level client) I've encountered an inconsistency regarding extended bounds in date histogram aggregation creation. In short, if extended bounds are specified in Java API, both min and max must be not-null and not empty. Such enforcement is not done by Elasticsearch server, which accepts JSON request with even both min and max as null's, which will simply have no effect.

Let's start with some sample bit of data:

POST /test-extbounds/_doc

And JSON request first:

    "query": {
        "match_all": {}
    "aggregations": {
        "date": {
            "date_histogram": {
                "field": "date",
                "calendar_interval": "1M",
                "min_doc_count": 0,
                "extended_bounds": {
                    "min": "2022-01",
                    "max": null

The following request will return 4 buckets, 3 of them with 0 doc count. That's what I would expect. However, I've tried to recreate that in new Java API client.

        var dateHistogram = AggregationBuilders.dateHistogram()
                .extendedBounds(eb -> eb.min(FieldDateMath.of(fdm -> fdm.expr("2022-01"))));

        SearchRequest request = new SearchRequest.Builder()
                .query(query -> query.matchAll(maq -> maq))

The above code yields the exception:
co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'ExtendedBounds.max'.

Former RHLC allowed even specifying null while creating LongBounds:

        var dateHistogram = new DateHistogramAggregationBuilder("date")
                .extendedBounds(new LongBounds("2022-01", null));
        var searchRequest = new SearchRequestBuilder(null, SearchAction.INSTANCE)

The conclusion is that Elasticsearch server allows null as one of min, max parameters (actually, even both of them, which will simply have no effect) of extended bounds, RHLC allows building requests like that, but Java API does not. What's the official stance on this? Are nulls being allowed just unintended feature on server side (and RHLC)?

Edit 2: I've just discovered a workaround which involves null check disabling using this method:
Obviously it would be desired not to be forced to used that, however, before creating github issue, I'd like to know if that was intended or not :slight_smile:

1 Like

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