elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.63k stars 24.64k forks source link

ST_CENTROID_AGG returns POINT(NaN NaN) on empty records #106025

Open craigtaverner opened 6 months ago

craigtaverner commented 6 months ago

Elasticsearch Version

8.14

Installed Plugins

No response

Java Version

bundled

OS Version

all

Problem Description

If we aggregate over zero records, we get POINT (NaN NaN). I think the default behaviour in ES|QL is to return null instead of NaN, and in this case a null centroid, not null coordinates.

For example:

FROM airports
| WHERE ST_INTERSECTS(location, city_location)
| STATS centroid=ST_CENTROID_AGG(location), count=COUNT()

Returns:

centroid:geo_point  |  count:long
POINT (NaN NaN)     |  0

But should return:

centroid:geo_point  |  count:long
null                |  0

And a warning.

Steps to Reproduce

Create an index with two geo_point fields, but do not add any documents.

Query with:

FROM index | STATS centroid=ST_CENTROID_AGG(location, other_location), count=COUNT(*)

Logs (if relevant)

No response

elasticsearchmachine commented 6 months ago

Pinging @elastic/es-analytical-engine (Team:Analytics)

bpintea commented 4 months ago

Related: https://github.com/elastic/elasticsearch/issues/98698.