You mean like this
There are 2 types geo_distance results returned by distance or geo_shape these point are withing this shape circle
Take a look here for the query types and here for sorting
Example
Put in a few points
DELETE my-index-000001
PUT my-index-000001
{
"mappings": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
PUT my-index-000001/_doc/1
{
"text": "location 1",
"location": {
"lat": 41.12,
"lon": -71.34
}
}
PUT my-index-000001/_doc/2
{
"text": "location 2",
"location": {
"lat": 42.52,
"lon": -71.00
}
}
PUT my-index-000001/_doc/3
{
"text": "House in london",
"location": {
"lat": 51.5,
"lon": -0.127
}
}
Here is a search using intersect (Points withing the circle
NOTE : be carefull how you put in the coordinates it is lon, lat
# intersects not sorted
GET /my-index-000001/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"geo_shape": {
"location": {
"shape": {
"type": "circle",
"coordinates": [ -71.3, 41.1],
"radius": "500km"
},
"relation": "intersects"
}
}
}
]
}
}
}
Results Not Sorted (you could by adding the sort clause below but I just wanted to show you both)
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"text" : "location 1",
"location" : {
"lat" : 41.12,
"lon" : -71.34
}
}
},
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"text" : "location 2",
"location" : {
"lat" : 42.52,
"lon" : -71.0
}
}
}
]
}
}
Now a distance search and sorted.
# Distance plus sort.
GET /my-index-000001/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "500km",
"location": [ -71.3, 42.5 ] <!-- NOTE this needs to be the same field name as your geo_point s
}
}
}
},
"sort" : [
{
"_geo_distance" : {
"location" : [ -71.3, 42.5 ], <!-- NOTE this needs to be the same field name as your geo_point s
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "arc",
"ignore_unmapped": true
}
}
]
}
Results
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "2",
"_score" : null,
"_source" : {
"text" : "location 2",
"location" : {
"lat" : 42.52,
"lon" : -71.0
}
},
"sort" : [
24.69089016681285
]
},
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "1",
"_score" : null,
"_source" : {
"text" : "location 1",
"location" : {
"lat" : 41.12,
"lon" : -71.34
}
},
"sort" : [
153.48501594012578
]
}
]
}
}