Running Queries

Running Queries

You can run queries using the Analytics Workbench, the command line query tool, cbq; or directly through the REST API.

Using the Analytics Workbench

A custom standalone Analytics Workbench is available with the Developer Preview.
  1. Open a browser and go to http://localhost:8095 to access the Analytics Workbench.

    We recommend Google Chrome or Mozilla Firefox browsers.

    Note: For the Docker image, the URL may be different as explained in the Using Docker section.
  2. Enter the following test query and click Execute:
    SELECT "Hello, beer!" AS greeting;
    Note: You must press the Execute button in the Analytics Workbench; unlike Query Workbench, pressing Enter or Return will not immediately execute a statement because Analytics accepts multi-line statements.

Using the Command Line Query Tool

You can use the command line tool, cbq, to run queries. The cbq is the command line shell for executing queries against Couchbase Server. Analytics contains a special version of cbq that works with the analytics service and can execute multi-line statements. Make sure you use the version of cbq located in your Analytics install folder.

  1. Run cbq with the following options:

    -b=on - enables batch-mode which is required to send multi-line statements as a batch.

    -e - specifies the host and port for the query service.

  2. Run the following command and then enter the statements in cbq:
    $ cbq -b=on -e ""
    cbq> create bucket beerBucket with { "bucket": "beer-sample", "nodes": "" };
    cbq> create shadow dataset beers on beerBucket;
    cbq> connect bucket beerBucket with { "password": "" };
  3. Send the request to the server by running the following command:
    cbq> \;
    Note: You must enter this special terminating sequence to execute the request. This differs from the normal cbq, which does not accept multi-line inputs.
    	"requestID": "eabac576-befa-459a-a862-1d040c0be033",
    	"signature": "*",
    	"status": "success",
    	"metrics": {
    		"elapsedTime": "2.089955267s",
    		"executionTime": "2.083973092s",
    		"resultCount": "0",
    		"resultSize": "0"

Using the REST API

When the cluster is up, requests can be posted to Couchbase Server.

  1. Access http://localhost:8095/analytics/service that implements the same interface as the Couchbase query service.
  2. Using curl, where $FILE contains the name of a file on your file system, run the following command:

    curl -s --data pretty=true --data-urlencode statement@$FILE http://localhost:8095/analytics/service

You can also use the REST API to run analytic queries. For details, see Analytics REST API.

Here are some examples using curl:
  • To check the analytics version, run the following command:

    curl -v http://localhost:8095/analytics/version

  • To query the cluster, run the following command:

    curl -v http://localhost:8095/analytics/cluster