Creating a Query: Polygon-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.
The following query-body uses an array, each of whose elements is a string, containing two floating-point numbers; to specify the latitude and longitude of each of the corners of a polygon --; known as polygon points.
In each string, the lat
floating-point value precedes the lon.
Here, the last-specified string in the array is identical to the initial string, thus explicitly closing the box. However, specifying an explicit closure in this way is optional: the closure will be inferred by the Couchbase Server if not explicitly specified.
If a target data-location falls within the box, its document is returned.
The results are specified to be sorted on name
alone.
{
"query": {
"field": "geo",
"polygon_points": [
"37.79393211306212,-122.44234633404847",
"37.77995881733997,-122.43977141339417",
"37.788031092020155,-122.42925715405579",
"37.79026946582319,-122.41149020154114",
"37.79571192027403,-122.40735054016113",
"37.79393211306212,-122.44234633404847"
]
},
"sort": [
"name"
]
}
A subset of formatted output might appear as follows:
.
.
.
"hits": [
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "landmark_25944",
"score": 0.23634379439298683,
"sort": [
"4"
]
},
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "landmark_25681",
"score": 0.31367419004657393,
"sort": [
"alta"
]
},
{
"index": "test_geopoint_610cbb5808dfd319_4c1c5584",
"id": "landmark_25686",
"score": 0.31367419004657393,
"sort": [
"atherton"
]
},
.
.
.