Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
awojcik64 opened this issue Apr 18, 2023 · 1 comment · Fixed by #776
Closed

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

awojcik64 opened this issue Apr 18, 2023 · 1 comment · Fixed by #776
Labels
Area: Specification Related to the API spec used to generate client code

Comments

@awojcik64
Copy link

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.

@l-trotta
Copy link
Contributor

Hello, thank you so much for providing such a detailed report :) this is an issue with the API specification used to produce the Java code, yes those two fields min and max in ExtendedBounds should be optional. We will fix the issue in the specification and regenerate the java code, thanks again!

@l-trotta l-trotta added the Area: Specification Related to the API spec used to generate client code label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Specification Related to the API spec used to generate client code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants