Appendix A. Working with geospatial data

Geospatial data makes your search application location-aware. For example, to search for events that are close to you, to find restaurants in a certain area, or to see which park’s area intersects with the area of the city center, you’d work with geospatial data.

We’ll call events and restaurants in this context points because they’re essentially points on the map. We’ll put areas, such as a country or a rectangle that you draw on a map, under the generic umbrella of shapes. Geospatial search works with points, shapes, and various relations between them:

Distance between a point and another point— If where you are is a point and swimming pools are other points, you can search for the closest swimming pools. Or you can filter only pools that are reasonably close to you, or use aggregations to see how many of them are within 10 km, how many are between 10 and 20 km, and so on.

A shape containing a point— If you select an area on the map, like the area where you work, you can filter only restaurants that are in that area, or you can use the geo_bounds aggregation to find out which area a set of points belongs in.

A shape overlapping with another shape— For example, you can search for parks in the city center.

This appendix will show you how to search, sort, and aggregate documents in Elasticsearch, based on their distance from a reference point on the map. You’ll also learn how to search for points that fall into a rectangle and how to search shapes that intersect with a certain area you define on the map.