Skip to content

Add field validation for range aggregation field option #20773

@ppf2

Description

@ppf2

Elasticsearch version: 1.7, 2.3

Consider the following example, if field is set to a field that does not exist, no errors are thrown and instead only the range aggregation is returned and the max value is not returned.

PUT rangeagg
{
  "mappings": {
    "type":{
      "properties": {
        "intField1":{
          "type": "integer"
        },
        "intField2":{
          "type": "integer"
        }
      }
    }
  }
}

POST rangeagg/type/1
{
  "intField1": 4,
  "intField2": 3
}

GET /rangeagg/_search
{
  "aggs": {
    "test": {
      "range": {
        "field": "whatever", 
        "script" : "doc['intField1'].value - doc['intField2'].value",
        "ranges": [
          {
            "from": 0,
            "to": 2
          }
        ]
      },
      "aggs": {
        "max": {
          "max": {
            "field": "intField1"
          }
        }
      }
    }
  }
} 

Returns:

"aggregations": {
      "test": {
         "buckets": [
            {
               "key": "0.0-2.0",
               "from": 0,
               "from_as_string": "0.0",
               "to": 2,
               "to_as_string": "2.0",
               "doc_count": 0
            }
         ]
      }
   }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions