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"
}
}
}
}
}
}