N1ql to fetch Index definition

Hi All,

I am working on getting all indexes scripted from one environment from other.
I can get indexes names from below query by specifying bucket:
select RAW name from system:indexes where keyspace_id=‘namedDB’

Now my question is there any way that i can get Index definition using N1ql as in sql server we used to do
sp_helptext’Indexname’
It will show index definition.Is there any way in N1ql.If not how to extract definition of all indexes at once rather than going one by one.

Thanks
Ritz

1 Like

There is no direct statement in the N1QL. You need to build the statement using system:indexes.

You can try one of the following options

  1. Run the following command on each index node https://docs.couchbase.com/server/5.5/rest-api/get-statement-indexes.html
    curl -v Administrator:password@127.0.0.1:9102/getIndexStatement

  2. Use UI copy all definitions

  3. Checkout cbbackupmgr https://docs.couchbase.com/server/5.5/backup-restore/cbbackupmgr-restore.html

Thanks Vsr already using above methods given by you but wanted if we can precise it to more at query level.

Hi @Ritz,

You can also try this

Add whitelist described in Security section of https://docs.couchbase.com/server/5.5/n1ql/n1ql-language-reference/curl.html

SELECT RAW re 
FROM CURL("http://Administrator:password@127.0.0.1:9102/getIndexStatement",{}) AS re  ;
1 Like

Hi Vsr1,

Thanks for response.
SELECT RAW re
FROM CURL(“http://Administrator:password@127.0.0.1:9102/getIndexStatement”,{}) AS re ; this couldn’t fetch data.I used curl method.