Description
Today if you specify an aggregation with no field
or script
like so:
{
"size": 0,
"aggs": {
"the_terms": {
"terms": {
"size": 10
}
}
}
}
We throw an exception:
{
"type": "illegal_state_exception",
"reason": "value source config is invalid; must have either a field context or a script or marked as unwrapped"
}
The problem is that the exception is generated from what is an otherwise invalid ValuesSourceConfig object. E.g. when resolving we identify that there is no script or field, generate an invalid VSConfig, then later at the factory layer check to see if the VSConfig is valid and throw an exception.
Besides being confusing from a code perspective, it also means we don't throw until we've already broadcast the request to the cluster. We should instead fail during parsing because there is no sensible reason to omit both field and script (I don't think?)
Note: There are a few instances (e.g. ParentAggregationBuilder
) that use the mutability of VSConfig which may be why we ended up in this situation. But even if we don't fix that part of VSConfig, we can head off these scenarios at the parse layer first.
Related to #42949