| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 | [[search-aggregations-metrics-geocentroid-aggregation]]=== Geo Centroid AggregationA metric aggregation that computes the weighted centroid from all coordinate values for a <<geo-point>> field.Example:[source,js]--------------------------------------------------{    "query" : {        "match" : { "crime" : "burglary" }    },    "aggs" : {        "centroid" : {            "geo_centroid" : {                "field" : "location" <1>            }        }    }}--------------------------------------------------<1> The `geo_centroid` aggregation specifies the field to use for computing the centroid. (NOTE: field must be a <<geo-point>> type)The above aggregation demonstrates how one would compute the centroid of the location field for all documents with a crime type of burglaryThe response for the above aggregation:[source,js]--------------------------------------------------{    ...    "aggregations": {        "centroid": {            "location": {                "lat": 80.45,                "lon": -160.22            }        }    }}--------------------------------------------------The `geo_centroid` aggregation is more interesting when combined as a sub-aggregation to other bucket aggregations.Example:[source,js]--------------------------------------------------{    "query" : {        "match" : { "crime" : "burglary" }    },    "aggs" : {        "towns" : {            "terms" : { "field" : "town" },            "aggs" : {                "centroid" : {                    "geo_centroid" : { "field" : "location" }                }            }        }    }}--------------------------------------------------The above example uses `geo_centroid` as a sub-aggregation to a <<search-aggregations-bucket-terms-aggregation, terms>> bucket aggregationfor finding the central location for all crimes of type burglary in each town.The response for the above aggregation:[source,js]--------------------------------------------------{    ...    "buckets": [       {           "key": "Los Altos",           "doc_count": 113,           "centroid": {              "location": {                 "lat": 37.3924582824111,                 "lon": -122.12104808539152              }           }       },       {           "key": "Mountain View",           "doc_count": 92,           "centroid": {              "location": {                 "lat": 37.382152481004596,                 "lon": -122.08116559311748              }           }        }    ]}--------------------------------------------------
 |