Created
June 14, 2017 21:50
-
-
Save sl-digital/c08cdc4dd8a65b70499e28376c1d5cd1 to your computer and use it in GitHub Desktop.
ElasticSearch Radius Search with Distance Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$lat = $this->listing->latitude; | |
$lon = $this->listing->longitude; | |
$params = [ | |
"index" => "listings", | |
"body" => [ | |
"from" => 0, | |
"size" => 26, | |
"query" => [ | |
"bool" => [ | |
"must" => [ | |
"match_all" => (object) [] | |
], | |
"filter" => [ | |
"geo_distance" => [ | |
"distance" => "5mi", | |
"location" => [ | |
"lat" => $lat, | |
"lon" => $lon | |
], | |
"unit" => "mi" | |
] | |
] | |
] | |
], | |
"_source" => (object) [], | |
"sort" => [ | |
"_script" => [ | |
"type" => "number", | |
"script" => [ | |
"lang" => "painless", | |
"inline" => "doc['location'].planeDistance($lat,$lon) * (0.000621371)" | |
], | |
"order" => "asc" | |
] | |
] | |
] | |
]; | |
$resp = $this->client->search($params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment