Creating a Query: Rectangle-Based
Note that a detailed example for Geopoint index creation and also executing queries can be found at Geopoint Index Creation and running queries Geopoint Radius Queries.
In addition detailed information on performing queries with the Search REST API can be found in Searching with the REST API; which shows how to use the full curl
command and how to incorporate query-bodies into your cURL requests.
In the following query-body, the top_left
of a rectangle is expressed by means of an array of two floating-point numbers, specifying a longitude of -2.235143
and a latitude of 53.482358
.
The bottom_right
is expressed by means of key-value pairs, specifying a longitude of 28.955043
and a latitude of 40.991862
.
The results are specified to be sorted on name
alone.
{
"from": 0,
"size": 10,
"query": {
"top_left": [-2.235143, 53.482358],
"bottom_right": {
"lon": 28.955043,
"lat": 40.991862
},
"field": "geo"
},
"sort": [
"name"
]
}
A subset of formatted output might appear as follows:
.
.
.
"hits": [
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "landmark_16144",
"score": 0.004836809397039384,
"sort": [
"02"
]
},
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "hotel_9905",
"score": 0.01625607942050202,
"sort": [
"1"
]
},
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "hotel_16460",
"score": 0.004836809397039384,
"sort": [
"11"
]
},
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "hotel_21674",
"score": 0.010011952055063241,
"sort": [
"17"
]
},
.
.
.