Getting Views Information
To retrieve views information, access any server node in a cluster on port 8092.
HTTP method and URI
GET /[bucket-name]/_design/[ddoc-name]/_view/[view-name]
Where:
-
bucket-name is the name of the bucket.
-
ddoc-name is the name of the design document that contains the view.
-
view-name is the name of the corresponding view within the design document.
Development view, the ddoc-name
is prefixed with dev_
.
For example, the design document beer
is accessible as a development view using dev_beer
.
Production views are accessible using their name only.
Request data |
None |
Response data |
JSON of the rows returned by the view |
Authentication required |
No |
Parameters (optional):
Parameters | Type | Description |
---|---|---|
|
boolean |
Return the documents in descending by key order. |
|
string |
Stop returning records when the specified key is reached. Key must be specified as a JSON value. |
|
string |
Stop returning records when the specified document ID is reached. |
|
boolean |
Use the full cluster data set (development views only). |
|
boolean |
Group the results using the reduce function to a group or single row.
Note: Do not use |
|
numeric |
Specify the group level to be used.
Note: Do not use |
|
boolean |
Specifies whether the specified end key is included in the result.
Note: Do not use |
|
string |
Return only documents that match the specified key. Key must be specified as a JSON value. |
|
array |
Return only documents that match each of keys specified within the given array. Key must be specified as a JSON value. Sorting is not applied when using this option. |
|
numeric |
Limit the number of the returned documents to the specified number. |
|
string |
Sets the response in the event of an error. Supported values:
|
|
boolean |
Use the reduction function. |
|
numeric |
Skip this number of records before starting to return the results. |
|
string |
Allow the results from a stale view to be used. Supported values:
|
|
string |
Return records with a value equal to or greater than the specified key. Key must be specified as a JSON value. |
|
string |
Return records starting with the specified document ID. |
Syntax
Curl request syntax:
GET http://[localhost]:8092/[bucket-name]/_design/[ddoc-name]/_view/[view-name]
To access a view stored within an SASL password-protected bucket, include the bucket name and bucket password within the URL of the request:
GET http://[bucket-name]:[password]@[localhost]: \ 8092/[bucket-name]/_design/[ddoc-name]/_view/[view-name]
Additional arguments to the URL request can be used to select information from the view, and provide limit, sorting and other options. |
To output only ten items:
GET http://[localhost]:8092/[bucket-name]/_design/[ddoc-name]/_view/[view-name]?limit=10
The formatting of the URL follows the HTTP specification.
The first argument is separated from the base URL using a question mark ( ? ).
Additional arguments are separated using an ampersand ( & ).
Special characters are quoted or escaped according to the HTTP standard rules.
|
Example
Curl request example:
In the following example, an empty development view is created with a view name, johnView, and a design document name, _design/dev_john in the bucket, test2.
curl -u Administrator:password -X GET \ http://10.5.2.117:8092/test2/_design/dev_john/_view/johnView
Response
View responses are JSON structures containing information about the number of rows in the view and the individual view information.
The following shows an empty View result from the previous example.
{ "rows": [], "total_rows": 0 }
The following shows a populated View result:
{ "total_rows": 576, "rows" : [ {"value" : 13000, "id" : "James", "key" : ["James", "Paris"] }, {"value" : 20000, "id" : "James", "key" : ["James", "Tokyo"] }, {"value" : 5000, "id" : "James", "key" : ["James", "Paris"] }, … ] }
The JSON response returns the following fields:
-
total_rows
A count of the number of rows of information within the stored View. This shows the number of rows in the full View index, not the number of rows in the returned data set.
-
rows
An array, with each element of the array containing the returned view data, consisting of the value, document ID that generated the row, and the key.
In the event of an error or incorrect parameters, the HTTP response is a JSON structure with a basic error
field and a more detailed reason
field.
For example:
{ "error":"bad_request", "reason":"invalid UTF-8 JSON: {{error,{1,\"lexical error: \ invalid char in json text.\\n\"}},\n\"Paris\"}" }
With client libraries, error response behavior might differ between client SDKs, but in all cases, an invalid query triggers an error or exception. |