Skip to content

Allow bucket_selector to be used for TopHits and TopMetrics aggs #73429

@matriv

Description

@matriv

Currently both TopHits and TopMetrics aggs don't allow the use of bucket selector which in turn
doesn't allow the translation of an SQL query with a HAVING clause on such aggregations to be used:
e.g.:

SELECT gender, FIRST(salary, birth_date) as first FROM test_emp GROUP BY gender HAVING first > 10000 ORDER BY gender 

This query would translate to something like this in query DSL:

{ "aggregations": { "groupby": { "composite": { "size": 1000, "sources": [ { "754ec7e7": { "terms": { "field": "gender", "missing_bucket": true, "order": "asc" } } } ] }, "aggregations": { "d08ba905": { "top_metrics": { "metrics": { "field": "salary" }, "sort": { "birth_date": "asc" }, "size": 10 } }, "having.d08ba905": { "bucket_selector": { "buckets_path": { "a0": "d08ba905" }, "script": { "source": "InternalQlScriptUtils.nullSafeFilter(InternalQlScriptUtils.gt(InternalQlScriptUtils.nullSafeCastNumeric(params.a0,params.v0),params.v1))", "lang": "painless", "params": { "v0": "INTEGER", "v1": 1000 } }, "gap_policy": "skip" } } } } } } 

which throws:

"caused_by": { "type": "aggregation_execution_exception", "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: [InternalTopHits] at aggregation [d08ba905]" } 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions