Filter against geo_point in an array of nested objects
Following is an example on applying filter query against geo_point with an nested object. I have used mongoosastic which is a Mongoose plugin to create indexing in elasticsearch.
Mongoose geoLocation data model
geoLocation: { type: { type: String, default: 'Point' }, coordinates: [Number]}
Create mapping on geoLocation field
Model.createMapping({ "mappings": { "event": { "properties": { "geoLocation": { "type": "nested", "properties": { "coordinates": { "type": "geo_point", "lat_lon": true } } } } } } }, function(err, mapping) { if (!err) { console.log('mapping created!'); } });
Query with geo filter
{ "query": { "filtered": { "query": { "multi_match": { "query": "Pop", "fields": ["name","city"], "type": "phrase_prefix" } }, "filter": { "nested": { "path": "geoLocation", "query": { "filtered": { "filter": { "geo_distance": { "distance": "5km", "geoLocation.coordinates": { "lat": 19.1074861, "lon": 72.9156988 } } } } } } } } }}