CB 6.x: How to create index from JSON output by N1QL query to system:indexes?

Hello. I’m wondering if there is an easy way to create an index from the JSON output generated by the following query:

SELECT * FROM system:indexes

The format of the JSON is

[
  {
    "indexes": {
      "condition": "(`type` = \"TheType\")",
      "datastore_id": "http://127.0.0.1:8091",
      "id": "f27386d2fc35f6a2",
      "index_key": [
        "`owner`",
        "`startDate`",
        "`createdAt`"
      ],
      "keyspace_id": "test",
      "name": "idx_TheType_StartDate",
      "namespace_id": "default",
      "state": "online",
      "using": "gsi"
    }
  }
]

Is there a N1QL query to create an index based on the JSON output above? Or do I need to parse the JSON and generate the CREATE INDEX query string?

@jcnw There is no built-in query to do that, and system:indexes will not contain all the information to exactly reproduce the original index. You might find the following more helpful if you have administrator access:

Run the following against any one of the Index nodes. (It will automatically gather information from all Index nodes.) The output is JSON and will contain the full CREATE INDEX statement for each index in the “definition” field of the objects:

curl -X GET -u <administrator_user>:<password> "http://<host>:9102/getIndexStatus"

If using https the port will be 19102 instead of 9102.

2 Likes