Query non-exist fields exception

Hi

I have found some inconsistency about querying non-exist fields
for most of the cases , exception will be thrown only in nested range aggregation,
If I query non-exist fields in query context or other types of aggregation, there is no exception and only return empty results

For example
GET /index_name/_search
{
"from":0,
"size": 0,
"query": {
"nested": {
"path": "test",
"query": {
"match": {
"index_type": "testA"
}
}
}
},
"aggs": {
"test": {
"nested": {
"path": "mypath"
},
"aggs": {
"test1": {
"range": {
"field": "non-existing field",
"ranges": [
{
"from": "2024-01-01"
}
]
}
}
}
}
}
}

there will be error below
{
"error": {
"root_cause": [
{
"type": "number_format_exception",
"reason": "For input string: "2024-01-01""
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the Elastic Stack and Solutions Help · Forums and Slack | Elastic page. It contains also lot of useful information on how to ask for help.