Skip to content

Reverting "making range aggregation untagged union (#2725)" #4243

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/steps/validate-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,7 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma

validateValueOf(valueOf, openGenerics)
} else if (variants.kind === 'untagged') {
if (fqn(parentName) !== '_types.aggregations:AggregationRange' &&
fqn(parentName) !== '_types.query_dsl:DecayFunction' &&
if (fqn(parentName) !== '_types.query_dsl:DecayFunction' &&
fqn(parentName) !== '_types.query_dsl:DistanceFeatureQuery' &&
fqn(parentName) !== '_types.query_dsl:RangeQuery') {
throw new Error(`Please contact the devtools team before adding new untagged variant ${fqn(parentName)}`)
Expand Down
61 changes: 32 additions & 29 deletions specification/_types/aggregations/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class DateRangeAggregation extends BucketAggregationBase {
/**
* Array of date ranges.
*/
ranges?: DateAggregationRange[]
ranges?: DateRangeExpression[]
/**
* Time zone used to convert dates from another time zone to UTC.
*/
Expand All @@ -306,6 +306,33 @@ export class DateRangeAggregation extends BucketAggregationBase {
keyed?: boolean
}

/**
* A date range limit, represented either as a DateMath expression or a number expressed
* according to the target field's precision.
*
* @codegen_names expr, value
*/
// ES: DateRangeAggregationBuilder.innerBuild()
export type FieldDateMath = DateMath | double

export class DateRangeExpression {
/**
* Start of the range (inclusive).
*/
from?: FieldDateMath
/**
* Custom key to return the range with.
*/
key?: string
/**
* End of the range (exclusive).
*/
to?: FieldDateMath
}

/**
* @ext_doc_id search-aggregations-bucket-diversified-sampler-aggregation
*/
export class DiversifiedSamplerAggregation extends BucketAggregationBase {
/**
* The type of value used for de-duplication.
Expand Down Expand Up @@ -661,48 +688,24 @@ export class RangeAggregation extends BucketAggregationBase {
format?: string
}

/**
* @codegen_names untyped, date, number, term
* @variants untagged untyped=_types.aggregations.UntypedAggregationRange
*/
export type AggregationRange =
| UntypedAggregationRange
| DateAggregationRange
| NumberAggregationRange
| TermAggregationRange

export class AggregationRangeBase<T> {
export class AggregationRange {
/**
* Start of the range (inclusive).
*/
from?: T
from?: double | null
/**
* Custom key to return the range with.
*/
key?: string
/**
* End of the range (exclusive).
*/
to?: T
to?: double | null
}

export class NumberAggregationRange extends AggregationRangeBase<double> {}

export class TermAggregationRange extends AggregationRangeBase<string> {}

export class UntypedAggregationRange extends AggregationRangeBase<UserDefinedValue> {}

export class DateAggregationRange extends AggregationRangeBase<FieldDateMath> {}

/**
* A date range limit, represented either as a DateMath expression or a number expressed
* according to the target field's precision.
*
* @codegen_names expr, value
* @ext_doc_id search-aggregations-bucket-rare-terms-aggregation
*/
// ES: DateRangeAggregationBuilder.innerBuild()
export type FieldDateMath = DateMath | double

export class RareTermsAggregation extends BucketAggregationBase {
/**
* Terms that should be excluded from the aggregation.
Expand Down