0

I have an elastic index with many documents. A document represents some event. Every event has a date and geolocation.

I would like to send queries like these: "Some event in LA", "Some event tomorrow", "Some event near me"...

How could I build this solution with elastic?

degratnik
  • 830
  • 2
  • 9
  • 19

1 Answers1

1

Elasticsearch have some tools to do that simple. For example we have a pin in a specific location (lat, long) like this:

{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

To search in a range of 200km we can do a query like this:

{
    "bool" : {
        "must" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

Is really easy And for dates you can use the a range query like this:

{
    "range" : {
        "date" : {
            "gte" : "now/d",
            "lt" :  "now+1d/d"
        }
    }
}

For more example take a look in the documentation https://www.elastic.co/guide/en/elasticsearch/guide/current/geoloc.html https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

Waldemar Neto
  • 826
  • 6
  • 17
  • Thank you. I know this. I would like to convert the command word (tomorrow, near me, in LA) from search query into complex DSL query, – degratnik Feb 19 '16 at 06:56