Example for ElasticSearch geo distance filter


curl -XDELETE 'http://localhost:9200/twitter/'
curl -XPUT 'http://localhost:9200/twitter/'

curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
    "tweet" : {
        "properties" : {
            "locations" : {"type" : "geo_point"}
        }
    }
}'

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{ 
    "user": "kimchy", 
    "postDate": "2009-11-15T13:12:00", 
    "message": "Trying out Elastic Search, so far so good?",
    "locations" : [{
        "lat" : 50.00,
        "lon" : 10.00
    },
    {
        "lat" : 40.00,
        "lon" : 9.00
    }]
}'

curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{ 
    "user": "kimchy", 
    "postDate": "2009-11-15T13:12:00", 
    "message": "Trying out Elastic Search, so far so good?",
    "locations" : [{
        "lat" : 30.00,
        "lon" : 8.00
    },
    {
        "lat" : 20.00,
        "lon" : 7.00
    }]
}'

curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
    "query": {
        "filtered" : {
            "query" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "20km",
                    "tweet.locations" : {
                        "lat" : 40.00,
                        "lon" : 9.00
                    }
                }
            }
        }
    }
}'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s