A newer version of this documentation is available.

View Latest

Getting Views Information

  • reference
    +
    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):

    Table 1. Views parameters
    Parameters Type Description

    descending

    boolean

    Return the documents in descending by key order.

    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.

    full_set

    boolean

    Use the full cluster data set (development views only).

    group

    boolean

    Group the results using the reduce function to a group or single row. Note: Do not use group with group_level because they are not compatible.

    group_level

    numeric

    Specify the group level to be used. Note: Do not use group_level with group because they are not compatible.

    inclusive_end

    boolean

    Specifies whether the specified end key is included in the result. Note: Do not use inclusive_end with key or keys.

    key

    string

    Return only documents that match the specified key. Key must be specified as a JSON value.

    keys

    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.

    limit

    numeric

    Limit the number of the returned documents to the specified number.

    on_error

    string

    Sets the response in the event of an error.

    Supported values:

    • continue : Continue to generate view information in the event of an error, including the error information in the view response stream.

    • stop : Stop immediately when an error condition occurs. No further view information is returned.

    reduce

    boolean

    Use the reduction function.

    skip

    numeric

    Skip this number of records before starting to return the results.

    stale

    string

    Allow the results from a stale view to be used.

    Supported values:

    • false : Force a view update before returning data.

    • ok : Allow stale views.

    • update_after : Allow stale view, update view after it has been accessed.

    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.

    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.