Having trouble creating aggregation

I have an index with following fields, among others:

  • yearBuilt (a number like 1975 that indicates the year a house was constructed)
  • zipCode

I want to create an aggregation which shows the average YearBuilt by each ZipCode. I got the following, but not sure how to filter out documents that don't have the ZipCode or YearBuilt columns?

POST /properties/_search
{
  "size": 0, 
  "aggs": {
    "zips": {
      "terms": {
        "field": "zipCode",
        "size": 100
      },
      "aggs": {
        "avgYearBuilt": {
          "avg": {
            "field": "yearBuilt"
          }
        }
      }
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.