Command line index creation

Is it possible to create an index via command line? So far I am able to do so via cbq. I am scripting the server setup and would like to be able to create all my indexes via scripts.

Thanks

1 Like

Hi @yev!

You can use the --script option to execute a single N1QL query and exit the shell. For instance:

cbq --script="CREATE PRIMARY INDEX ON `bucket`"

For more information about cbq, check out the docs here: http://developer.couchbase.com/documentation/server/4.5/tools/cbq-shell.html

Let me know if that works for you.

1 Like

@matthew.groves, seems this only applies to v4.5, is that correct? I am currently on 4.1

1 Like

Yes, that’s correct. A lot of new functionality was added to cbq for 4.5.

For 4.1, you should be able to ‘pipe’ in the query from the command line (that’s going to vary based on which OS you are using)

You can also use the REST API to execute N1QL queries (see the REST API docs here: http://developer.couchbase.com/documentation/server/4.0/n1ql/n1ql-rest-api/executen1ql.html), and you can execute that from the command line as well (again, going to vary based on which OS you are using).

1 Like

You can use the scripting (input file or reading a file into cbq shell) facility in cbq shipped with 4.5 server.
http://developer.couchbase.com/documentation/server/current/tools/cbq-shell.html

2 Likes