I need to get last registered record for a serial number-or serial numbers- in a restricted area, also I should clustering these records upon zoom precision in map. I'm using Elasticsearch and I've mapped my document in this shape:
{
"mappings": {
"AssetStatus": {
"properties": {
"location": {
"type": "geo_point"
},
"createdate": {
"type": "date"
},
"serialnumber": {
"type": "text",
"fielddata": "true"
}
}
}
}
}
thus, I've write this query.
{
"query": {
"bool": {
"must": [
{
"term": {
"serialnumber": "sn2"
}
},
{
"geo_bounding_box": {
"location": {
"top_left": "52.4, 4.9",
"bottom_right": "52.3, 5.0"
}
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 0,
"aggregations": {
"SerialNumberGroups": {
"terms": {
"field": "serialnumber"
},
"aggs": {
"tops": {
"top_hits": {
"sort": [
{
"createdate": {
"order": "desc"
}
}
],
"size": 1
},
"aggs": {
"geohash_grid": {
"field": "location",
"precision": 12
}
}
}
}
}
}
}
In this query, at the first I restrict documents depend on their serial numbers and their location, thus I group by query by serial number and order by createdate to get last registered record of each serial number in the area. the problem is in last part of query, when I should cluster result with geohash_grid. I Get this error
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [geohash_grid]",
"line": 1,
"col": 374
}
],
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [geohash_grid]",
"line": 1,
"col": 374
},
"status": 400