Basic Windows setup for cbq

#1

Hi,

I have downloaded the cbq tool from https://issues.couchbase.com/browse/MB-13062?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

I tried to run a simple beer-sample query by running below command and query:
cbq --engine="http://localhost:8091"
cbq> SELECT * FROM beer-sample WHERE city = ‘San Francisco’;

I am getting this response : Requested resource not found.

This response is for any bucket i have in my local system.

I have tried to follow steps from the thread: N1QL - Getting Started

Can you please point to a thread and help in resolving the same? Also if any particular steps to run the n1ql queries from a java code will be really helpful.

Thanks
Bharat

#2

would you be able to install Couchbase Server 4.0 Release Candidate? N1QL DP4 with an external process for cbq-engine is quite outdated now… CB4.0-RC has been announced with updated instructions here.

If you can’t, for whatever reason, upgrade the localhost couchbase instance then make sure you are also running cbq-engine.exe as stated in the topic you linked (in a separate console that you shouldn’t close, this is not a daemon process).

cbq-engine is the executable that processes N1QL queries in the N1QL developer preview, while cbq is the command line N1QL client, so you need both.

#3

i tried:
\Desktop\cbq-dp4>cbq-engine.exe
_time=“2015-09-08T17:58:21+05:30” _level=“ERROR” _msg="Invalid datastore uri: "

i have also tried :
cbq-engine.exe http://localhost:8091
cbq-engine “http://localhost:8091

all have the same response. i have not yet upgraded my couchbase server to version 4.0. If its necessary , i will reply back once i downoad and upgrade it.

#4

that’s because you’re missing the -datastore parameter (it was -datastore in dp4, -couchbase apparently in dp3)…

try cbq-engine.exe -datastore=http://localhost:8091 (this connects the query service to the couchbase node)

then in another console cbq.exe -engine=http://localhost:8093/ (this launches a query client on the previously started local query service).

CB4.0 has query service embedded so the first step is not required anymore with it…

Also the query service is more advanced, and cbq client may have had a few bugs fixed so make sure to use the one from the bin folder of your Couchbase installation, not the one from CBQ-DP4.

After you make the cbq client work, make sure to create a primary index on the bucket your want to query, as stated in the various tutorials:

CREATE PRIMARY INDEX ON `someBucket`;
#5

Thanks a lot Simon,
For CB 3.0:

this seems to be working to the point of creating index with below query:

the above query seemed to worked fine with beer-sample bucket. further which it seems to fail to fetch json documents needed.

Queries I have tried so far:
cbq.exe> CREATE PRIMARY INDEX ON beer-sample;
{
“requestID”: “4f3f95d7-49d1-40b1-afa1-208d4084d923”,
“signature”: null,
“results”: [
],
“status”: “success”,
“metrics”: {
“elapsedTime”: “8.3943208s”,
“executionTime”: “8.393321s”,
“resultCount”: 0,
“resultSize”: 0
}
}
cbq.exe> SELECT * FROM beer-sample WHERE country= “United States”;
{
“requestID”: “e2370227-5438-42af-9bc0-ac85009fdd81”,
“errors”: [
{
“code”: 5000,
“msg”: “syntax error”
}
],
“status”: “fatal”,
“metrics”: {
“elapsedTime”: “0”,
“executionTime”: “0”,
“resultCount”: 0,
“resultSize”: 0,
“errorCount”: 1
}
}

cbq.exe> SELECT * FROM default USE KEYS ‘21st_amendment_brewery_cafe’;
{
“requestID”: “b2107c2c-67c2-4d99-bc53-1476fa31b250”,
"signature": {
"": ""
},
“results”: [
],
“status”: “success”,
“metrics”: {
“elapsedTime”: “1.0551055s”,
“executionTime”: “1.0551055s”,
“resultCount”: 0,
“resultSize”: 0
}
}

cbq.exe> SELECT * FROM beer-sample USE KEYS '21st_amendment_brewery_cafe’;
{
“requestID”: “c9a9f69e-472e-46d5-86cb-71376cad7c91”,
“errors”: [
{
“code”: 5000,
“msg”: “syntax error”
}
],
“status”: “fatal”,
“metrics”: {
“elapsedTime”: “0”,
“executionTime”: “0”,
“resultCount”: 0,
“resultSize”: 0,
“errorCount”: 1
}
}

I would like to also mention that my Couchbase installation folder doesn’t have the cbq-engine or cbq executable file. may be i goofed up while installation, but am not able to find it in the bin folder or otherwise.

For CB 4.0:

I am facing connection issue as below:

C:\Program Files\Couchbase\Server\bin>cbq.exe -engine=http://localhost:8093/
Couchbase query shell connected to “http://localhost:8093/” . Type Ctrl-D to exit.
cbq.exe> SELECT * FROM beer-sample USE KEYS ‘21st_amendment_brewery_cafe’;
←[31m ERROR 5000 : Post “http://localhost:8093/query”: dial tcp 127.0.0.1:8093: ConnectEx tcp: No connection could be made because the target machine actively refused it. ←[0m
cbq.exe> CREATE PRIMARY INDEX ON beer-sample;
←[31m ERROR 5000 : Post “http://localhost:8093/query”: dial tcp 127.0.0.1:8093: ConnectEx tcp: No connection could be made because the target machine actively refused it. ←[0m

So currently the queries are failing for some reason I am not able to resolve. If possible can you guide me further?

#6

for 4.0: pls make sure you have the query service running and cbq is pointing at the node running the query service (if this is a multi node cluster). the error indicates you don’t have query service (cbq-engine) running.
for all n1ql statements, pls make sure you use back ticks to escape all names with -. for example select * frombeer-sample` otherwise we treat the reference to beer-reference differently.
-cihan

#7

Thanks for the tip. The query engine fix seems to be working now. Now I am facing issue with below queries:

cbq.exe> select * from `beer-sample`;
{
    "requestID": "fd8063ca-7a83-44b9-9c0f-0e9ed9faf080",
    "errors": [
        {
            "code": 4000,
            "msg": "No primary index on keyspace beer-sample. Use CREATE PRIMARY INDEX to create one."
        }
    ],
    "status": "fatal",
    "metrics": {
        "elapsedTime": "22.0022ms",
        "executionTime": "22.0022ms",
        "resultCount": 0,
        "resultSize": 0,
        "errorCount": 1
    }
}
cbq.exe> CREATE PRIMARY INDEX ON `beer-sample`;
{
    "requestID": "c83ae314-82ab-4e8f-98f1-6d3fa0e185c7",
    "signature": null,
    "results": [
    ],
    "errors": [
        {
            "code": 12005,
            "msg": "Indexer not implemented GSI may not be enabled"
        }
    ],
    "status": "errors",
    "metrics": {
        "elapsedTime": "1.0001ms",
        "executionTime": "1.0001ms",
        "resultCount": 0,
        "resultSize": 0,
        "errorCount": 1
    }
}

If anything I am missing, please let me know.

#8

:bulb: Tip: Please enclose code samples in triple backticks ` to show it as code, especially when you want to show some lines with a backtick like your CREATE PRIMARY INDEX statement above… At first sight it was confusing because it looked as if you had once again forgotten to escape beer-sample… I made an edit of your post accordingly, look at the source if you want to get the forum syntax right.

Are you now running Couchbase 4.0? If so, in the webconsole, do you have at least one node with query and index services active? You can see it in the third column of the Server Nodes section:

You should then connect cbq to that particular node and you should be able to create the index.

Let me know if you’re still using CB3.0, this is another beast entirely:

  • CB3.0 = query/index service as a separate executable, part of the CBQ-DP4 distribution which includes cbq and cbq-engine as well
  • CB4.0 = query/index part of the Couchbase Server distribution, to be activated on cluster creation (or when adding a new node to the cluster), cbq tool is provided in the bin folder of your Couchbase installation.
#9

Thanks for the reply.

Yes it is CB 4.0. also I do use back ticks now. it was omitted while formatting the comments here(maybe)
I can only see Data services in the console part of the couchbase console. Not able to see query services.

#10

Without a query and index service, N1QL can’t possibly work, so that explains that.

If your test cluster has multiple nodes, you can remove one CB4.0 node from the cluster, rebalance, add it back:
at this point, the webconsole will offer you to choose the services to use, make sure to check all of them. Rebalance again and connect to that node using CBQ.

If your test cluster is a single node, did you uncheck query and index upon installation? they should have been selected by default. If so unfortunately you’ll have to reinstall :warning: in order to get the installation wizard again (see the doc on how to uninstall).

:bulb: If you don’t want to lose your data, you may manage to skip this uninstallation if you can add a second node: add new node B, remove original A and rebalance. Then connect to second node webconsole and to the inverse operation: add A (select all 3 services), remove B, rebalance.

#12

I am facing similar issue as nbupadhaya

cbq.exe> CREATE PRIMARY INDEX ON beer-sample;
{
“requestID”: “c83ae314-82ab-4e8f-98f1-6d3fa0e185c7”,
“signature”: null,
“results”: [
],
“errors”: [
{
“code”: 12005,
“msg”: “Indexer not implemented GSI may not be enabled”
}
],
“status”: “errors”,
“metrics”: {
“elapsedTime”: “1.0001ms”,
“executionTime”: “1.0001ms”,
“resultCount”: 0,
“resultSize”: 0,
“errorCount”: 1
}
}

As mentioned by you I checked whether query and indexing services are active. All three services are there and I am using CB 4.0. Please help !

#13

if you’re indeed using CB 4.0 (GA) and both index and query services are active, this is much weirder. Is that a 1 node cluster? Are you sure you’re connecting cbq to this index+query cluster (and not eg. localhost if it’s not running locally)?

maybe @geraldss will have other ideas…

#14

Yes and it is one node cluster.

#15

@Svar it doesn’t look like the same issue as the OP but rather a deeper problem.

In the webconsole, can you see anything in the Logs tab? Please re-trigger the issue, look at the logs and maybe collect them (as described in the documentation) so that they are ready should a member of the index or query teams require them for further analysis.

I’d also start a new topic to get it more attention. (something like “got Indexer not implemented GSI on an index and query node”).

Sorry I can’t help you further but this doesn’t look like a simple misconfiguration, from what you told us.