Search code examples
couchbasesql++

N1ql to fetch Index definition


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


Solution

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

    You Can try one of the following option

    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
    4. 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 ;