How to query with Curl in couchbase

@prathibha I tried this:

root@database-server-02-Automation:~# curl -X POST -v -u admin:admin http://x.x.x.x:5984/query/service -d statement=CREATE%20PRIMARY%20INDEX%20primary_index%20ON%20default:default%20USING%20GSI

Note: Unnecessary use of -X or --request, POST is already inferred.

  • Trying x.x.x.x…

  • TCP_NODELAY set

  • Connected to x.x.x.x (x.x.x.x) port 5984 (#0)

  • Server auth using Basic with user ‘admin’

POST /query/service HTTP/1.1

Host: x.x.x.x:5984

Authorization: Basic YWRtaW46YWRtaW4=

User-Agent: curl/7.58.0

Accept: /

Content-Length: 87

Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 87 out of 87 bytes

< HTTP/1.1 404 Object Not Found

< Cache-Control: must-revalidate

< Connection: close

< Content-Length: 58

< Content-Type: application/json

< Date: Fri, 15 Nov 2019 06:04:27 GMT

< Server: CouchDB/2.3.1 (Erlang OTP/19)

< X-Couch-Request-ID: 01e04837e0

< X-CouchDB-Body-Time: 0

<

{“error”:“not_found”,“reason”:“Database does not exist.”}

  • Closing connection 0

root@database-server-02-Automation:~#

I want to create index for all a database lets say test . COuld you help?

@monisha_m_Singh: For your index, please try running:

curl -v http://localhost:8093/query/service -d ‘statement=CREATE PRIMARY INDEX ON default&creds=[{“user”:“admin”, “pass”:“password”}]’

Please note that the right port has to be used for query engine is 8093.

I am very new to couchbase, COuld you guide me create an index with curl on port 8093? I tried the above command but 8093 isnt open on my machine somehow, and im not sure how to start the smae on machine. Please help.

Please try opening required ports using information in below articles:
https://docs.couchbase.com/server/5.5/security/security-iptables.html

iptables -A INPUT -p tcp -m state –state NEW -m tcp –dport 8093 -j ACCEPT

You can also figure out what is your N1QL port using:
curl -v -X GET -u [admin]:[password] http://[ip-address]:8091/pools/default/nodeServices
You can double check the port being used for N1QL using above REST API.

you have to create index for that. if you dont have access please run same query after advise keyword and get the ddl or prepare ur own index and take help from db admins to do that.