Creating a Query: Polygon-Based
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": "geoIndex_661ef3af66ee41b5_54820232",
"id": "landmark_25944",
"score": 0.3214575420492102,
"sort": [
"4"
]
},
{
"index": "geoIndex_661ef3af66ee41b5_aa574717",
"id": "landmark_25681",
"score": 0.05294915340807584,
"sort": [
"alta"
]
},
{
"index": "geoIndex_661ef3af66ee41b5_13aa53f3",
"id": "landmark_25686",
"score": 0.28955510851484045,
"sort": [
"atherton"
]
},
.
.
.