GeoSpatial indexing with ElasticSearch

I have been playing with idea to have some kind of GeoSpatial search to meet my needs, something like what are the closest ATM or grocery stores nearby when travelling. This can be applied to a host of things which are location sensitive like nearby hospitals or something else as well. While thinking further on this landed with GeoSpatial indexing feature provided by ElasticSearch. In this article, let's briefly see a bit of this.

Pre-requisite

  • Java 7+
  • ElasticSearch 1.5.1
  • Sense plugin for Chrome

Sense plugin is optional. You can interact with ES using curl, but I prefer Sense for ease of use and the history it maintains.

The Application

Let's build an simple application that shall help us search nearby ATM's. You can add your custom category for this. We shall only focus on search part of it. It can be an Android App or a Web app. The App would send current Lat/Long and we shall return results matching the criteria.

ES Schema

Let's quickly see ES schema for this. Following is the simple schema we shall use. The geo_point is the key to have GeoSpatial indexing.

Sample screenshot

ESSchema

Let's add some sample data. I have added data based on my work location 🙂

Here is the screenshot

sampledata

Now let's see the query to get the result. We shall just see a simple query (can use all the powerful features of ES to fine tune the query including sorting etc)

The query shall return 2 result based on the data.

query-result

Cool, you have your local search engine.

This post is very simplictic usage, ES is veyr powerful in terms of what it can do in GeoSpatial domain as well as search domain. Further reading is recommending on https://www.elastic.co/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.