elastic / elasticsearch-specification

Elasticsearch full specification
Apache License 2.0
110 stars 66 forks source link

Regression on `AggregationRange` - incorrect types for `from` and `to` fields #2641

Open pgayvallet opened 1 week ago

pgayvallet commented 1 week ago

🐛 Wrong type

AggregationRange.from and AggregationRange.to were changed from string | number to number in https://github.com/elastic/elasticsearch-specification/pull/2552

From the PR:

AggregationRange accepting both double and string was probably established because at some point it was also used for RangeQuery, which accepts Objects for parameters to and from. But in the spec we just use it in GeoDistanceAggregation and RangeAggregation, both accepting only doubles. Since the java client generalizes string | double as just string, this results in the server throwing exceptions when called.

This was supposed to be done to address https://github.com/elastic/elasticsearch-java/issues/666, but the assumption that was used for the PR is wrong, For RangeAggrations at least, from and to do support string type value, for patterns such as now or now+X.

E.g from the Kibana repo:

https://github.com/elastic/kibana/blob/1c1e20afdb883fc279c5a06d4b71f8e577f8dad6/x-pack/plugins/task_manager/server/monitoring/workload_statistics.ts#L169-L180

flobernd commented 1 week ago

I think this type follows the same semantics as RangeQuery which means that it should accept arbitrary typed values for the from and to fields.

The corresponding RangeAggregate looks suspicious to me as well. We should double check the server code here as well.