Skip to content

Instantly share code, notes, and snippets.

Created April 17, 2012 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2406859 to your computer and use it in GitHub Desktop.
Save anonymous/2406859 to your computer and use it in GitHub Desktop.
ElasticSearch geo distance filter
//i create doc item using Elastica in PHP, database has about 150 000 items
$mapping->setProperties(
array(
'id' => array('type' => 'integer'),
'name' => array('type' => 'string'),
'quality' => array('type' => 'integer'),
'type_id' => array('type' => 'integer'),
'country' => array('type' => 'string'),
'city' => array('type' => 'integer'),
'location' => array('type' => 'geo_point')
)
);
//i use curl lib in PHP, in common the query is following:
curl -XGET "http://localhost:9200/database/object/_search" -d '
{ "size" : 2000,
"filter" : {
"geo_distance" : {
"distance" : "4km",
"location" : [48.85341, 2.3488],
"optimize_bbox" : "none",
"distance_type" : "arc"
}
}'
//returns 789 items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment