Query view
This method returns the list of result objects for files which match the query on a predefined view. Those objects contains following fields:
id- for use asstartkey_docidorendkey_docidin following querieskey- the first element of list returned by user defined mapping/spatial functionvalue- the second element of list returned by user defined mapping/spatial functiongeometry- describes geometry of data (only available in case of spatial views)
Currently, views are defined per space, i.e. the result will be limited to files and directories in a space for which the view was defined.
This operation supports also custom view query attributes as provided by Couchbase.
Additionaly, Couchbase spatial queries are possible using bbox query parameter.
These queries are possible on views which emit values conforming to the GeoJSON format.
This operation requires space_query_views privilege.
Example cURL requests
Get 4 files from view skipping first 10
With example map function used:
function (id, type, meta, ctx) {
if(type == 'custom_metadata' && meta['onexattr']) {
return [meta['onexattr'], id];
}
return null;
}
curl -H "X-Auth-Token: $TOKEN" -X GET \
https://$HOST/api/v3/oneprovider/spaces/$SPACE_ID/views/VIEW_NAME/query?skip=10&limit=4
[
{
"id": "fd18b793d446099ae84f8bd5c054ad34",
"key": 1,
"value": "00000000002C45416775696423633062636533343133336336636633393238336134323333396430656461393323737061636531"
},
{
"id": "2785dbd91120e341265f9ee2370ccf08",
"key": 2,
"value": "00000000002CF7DB6775696423396261373964653764643866336432393436323262313133393738643338383323737061636531"
},
{
"id": "60a9e6da61e12deeb3e6c688fe861c01",
"key": 3,
"value": "00000000002C47916775696423336330336538623730333439353233383631313966346139343731316631656323737061636531"
},
{
"id": "651d696a8446e92ab55de163f9b8594d",
"key": 4,
"value": "00000000002CA8906775696423633835366438613139666565336337666165623538303736356465383039356223737061636531"
},
...
]
Get list of files associated with geospatial coordinates
With example spatial function used:
function (id, type, meta, ctx) {
if(type == 'custom_metadata' && meta['onexattr']) {
return [meta['onexattr'], id];
}
return null;
}
curl -H "X-Auth-Token: $TOKEN" -X GET \
https://$HOST/api/v3/oneprovider/spaces/$SPACE_ID/views/$VIEW_NAME/query?spatial=true&stale=false
[
{
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"id": "36cfb018c312653e65b346c421d7a678",
"key": [[0, 0], [0, 0]],
"value": "00000000002C5DA36775696423663535633934306564393632656530666133663330633137393362333765356223737061636531"
},
{
"geometry": {
"type": "Point",
"coordinates": [5.1, 10.22]
},
"id": "972eb78ff8e262c4bebdc11799c20f51",
"key": [[5.1, 5.1], [10.22, 10.22]],
"value": "00000000002C678A6775696423363030666461383130623030386333616664363637396666653334366137656623737061636531"
}
]
Get file popularity for a specific space
curl -sSk -X GET -H "X-Auth-Token: $TOKEN" "https://$HOST/api/v3/oneprovider/spaces/$SPACE_ID/views/file-popularity/query?spatial=true&start_range=\[1,0,0,0,0,0\]&end_range=\[null,null,null,null,null,null\]"
Path parameters
| Parameter | Type & Description |
|---|---|
| sid required | string Space Id in which view exist. |
| view_name required | string Name of the view. |
Query parameters
| Parameter | Type & Description |
|---|---|
| descending | boolean Return the documents in descending order (by key). |
| key | string Return only documents that match the specified key. Key must be specified as a JSON value. |
| keys | string Return only documents that match any of the keys specified within the given array. Keys must be specified as a JSON array, escaped properly. Sorting is not applied when using this option. |
| limit | integer Limit the number of the returned documents to the specified number. |
| skip | integer Skip this number of records before starting to return the results. |
| startkey | string Return records with a value equal to or greater than the specified key. Key must be specified as a JSON value. |
| startkey_docid | string Return records starting with the specified document Id. |
| endkey | string Stop returning records when the specified key is reached. Key must be specified as a JSON value. |
| endkey_docid | string Stop returning records when the specified document Id is reached. |
| inclusive_end | boolean Specifies whether the specified end key is included in the result. Note: Do not use |
| stale | string Allow records from a stale view to be used. Allowed values are |
| bbox | string Specify the bounding box for a spatial query (e.g. ?bbox=-180,-90,0,0) |
| spatial | boolean Enable spatial type of query. When querying the file-popularity view, the |
| start_range | string Array specifying the range in spatial queries (e.g. |
| end_range | string Array specifying the range in spatial queries (e.g. |
Request Examples
oneprovider-rest-cli querySpaceView sid=$SPACE_ID view_name=$VIEW_NAME key=value1Responses
Query results returned successfully.
No schema provided.
Invalid request.
| Property | Type & Description |
|---|---|
error string Identifier representing internal error code. | |
error_description string Detailed error message. | |
Example
{
"error": "invalid_token",
"error_description": "Provided token could not be validated."
}Forbidden request.
| Property | Type & Description |
|---|---|
error string Identifier representing internal error code. | |
error_description string Detailed error message. | |
Example
{
"error": "invalid_token",
"error_description": "Provided token could not be validated."
}File not found.
| Property | Type & Description |
|---|---|
error string Identifier representing internal error code. | |
error_description string Detailed error message. | |
Example
{
"error": "invalid_token",
"error_description": "Provided token could not be validated."
}Internal server error.
| Property | Type & Description |
|---|---|
error string Identifier representing internal error code. | |
error_description string Detailed error message. | |
Example
{
"error": "invalid_token",
"error_description": "Provided token could not be validated."
}