ElasticSearch geo distance filter with multiple locations in array - possible? -


let's have bunch of documents in elasticsearch index. each documents has multiple locations in array, this:

{   "name": "foobar",   "locations": [     {       "lat": 40.708519,       "lon": -74.003212     },     {       "lat": 39.752609,       "lon": -104.998100     },     {       "lat": 51.506321,       "lon": -0.127140     }   ] } 

according elasticsearch reference guide

the geo_distance filter can work multiple locations / points per document. once single location / point matches filter, document included in filter.

so, possible create geo distance filter checks locations in array?

this doesn't seem work, unfortunately:

{   "filter": {     "geo_distance": {       "distance": "100 km",       "locations": "40, -105"     }   } } 

throws "queryparsingexception[[myindex] failed find geo_point field [locations]" since locations not single geo_point array of geo_points.

did specify geo_point mapping document?

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, far 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, far 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                     }                 }             }         }     } }' 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -