Skip to content

ExtendedBounds min and max values are required by the client, but not server #555

Closed
@awojcik64

Description

@awojcik64

Java API client version

7.17.9

Java version

11

Elasticsearch Version

7.17.9

Problem description

A quick prior note: I've asked about it here, since I wasn't sure if it was a client issue, actually. However, after creating that question I've discovered ApiTypeHelper::DANGEROUS_disableRequiredPropertiesCheck(boolean) method, which I am using as a workaround. After acknowledging its javadocs I am 90% sure it is a bug, hence this issue.

The issue regarding ExtendedBounds class is that its builder requires both min and max to be specified. This behavior is different from Elasticsearch server, which has no problem if one (or even both) are missing.

Let's start with some sample bit of data first.

POST /test-extbounds/_doc
{
  "date":"2022-04-01"
}

and a sample query:

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

That yields a response with 4 buckets (3 of them with 0 docs, which is fine.)

{
  "took" : 35,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test-extbounds",
        "_type" : "_doc",
        "_id" : "hVlblIcBVXy4uzZFJm5k",
        "_score" : 1.0,
        "_source" : {
          "date" : "2022-04-01"
        }
      }
    ]
  },
  "aggregations" : {
    "date" : {
      "buckets" : [
        {
          "key_as_string" : "2022-01-01T00:00:00.000Z",
          "key" : 1640995200000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2022-02-01T00:00:00.000Z",
          "key" : 1643673600000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2022-03-01T00:00:00.000Z",
          "key" : 1646092800000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2022-04-01T00:00:00.000Z",
          "key" : 1648771200000,
          "doc_count" : 1
        }
      ]
    }
  }
}

Things get complicated once I try to recreate that in Java API:

        var dateHistogram = AggregationBuilders.dateHistogram()
                .field("date")
                .format("yyyy-MM")
                .calendarInterval(CalendarInterval.Month)
                .minDocCount(0)
                .extendedBounds(eb -> eb.min(FieldDateMath.of(fdm -> fdm.expr("2022-01"))));

        SearchRequest request = new SearchRequest.Builder()
                .query(query -> query.matchAll(maq -> maq))
                .index("test-extbounds")
                .size(2)
                .aggregations(Map.of("test", dateHistogram.build()._toAggregation()))
                .build();

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

I've tried similar thing in Rest High Level Client, which is successful:

        var dateHistogram = new DateHistogramAggregationBuilder("date")
                .field("date")
                .format("yyyy-MM")
                .calendarInterval(DateHistogramInterval.MONTH)
                .minDocCount(0)
                .extendedBounds(new LongBounds("2022-01", null));
        var searchRequest = new SearchRequestBuilder(null, SearchAction.INSTANCE)
                .setQuery(QueryBuilders.matchAllQuery())
                .addAggregation(dateHistogram)
                .setIndices("test-extbounds").request();

Bare-json Elasticsearch API allows it, RHLC allows it, but not Java API client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SpecificationRelated to the API spec used to generate client code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions