QueryIndex.keyspace doesn't have SCOPE

Hi.
To get index information, I call Cluster.queryIndexes().getAllIndexes(“bucketName”).
It successfully returns QueryIndex.
But at QueryIndex, there is no scope information. QueryIndex.keyspace has only its collection name. When I call Cluster.queryIndexes().getAllIndexes(), there is no scope filter either.
So I cannot figure it out which scope this QueryIndex belongs to.

QueryIndex sample is:

	{
		"name": "IDX_NAME",
		"type": "gsi",
		"state": "online",
		"keyspace": "COLLECTION",
		"indexKey": [
			"`ABC`"
		]
	}

Is there any way to know which scope this index belongs to?
FYI, the courchbase SDK version is “couchbase”: “^3.2.5”.

Thanks a lot!

select * from system:indexes;

{
        "indexes": {
            "bucket_id": "default",
            "datastore_id": "http://127.0.0.1:8091",
            "id": "c22fc9f5ef8d1a98",
            "index_key": [
                "`c10`"
            ],
            "keyspace_id": "c1",
            "metadata": {
                "last_scan_time": null,
                "num_replica": 0,
                "stats": {
                    "last_known_scan_time": 0
                }
            },
            "name": "ix1",
            "namespace": "default",
            "namespace_id": "default",
            "scope_id": "s1",
            "state": "online",
            "using": "gsi"
        }
    }

bucket_id, scope_id, keyspace_id (which is collection). – This is collection based

{
        "indexes": {
            "datastore_id": "http://127.0.0.1:8091",
            "id": "77acda45afe0d113",
            "index_key": [
                "(`attr`.`id`)",
                "`attr`"
            ],
            "keyspace_id": "default",
            "metadata": {
                "last_scan_time": "2023-11-14T16:26:40.159-08:00",
                "num_replica": 0,
                "stats": {
                    "last_known_scan_time": 1700008000159744000
                }
            },
            "name": "idx6",
            "namespace": "default",
            "namespace_id": "default",
            "state": "online",
            "using": "gsi"
        }
    }

This has no bucket_id field i.e keyspace_id (is bucket) backward compatibility non collection based.

1 Like

The Java SDK’s QueryIndex class has a scopeName() accessor that returns an Optional<String>. If this is not present, the index is for the default scope, named “_default”. Same for collectionName().

Example:

cluster.queryIndexes().getAllIndexes("travel-sample")
  .forEach(index -> {
    String scopeName = index.scopeName().orElse("_default");
    String collectionName = index.collectionName().orElse("_default");
    System.out.println(scopeName + "." + collectionName + " : " + index.name());
  });

Thanks,
David

1 Like

That’s correct, you would fetch all the indexes and then filter by the index.scopeName() field that David mentions above.

Note if you want to get all indexes on a given collection, this is possible with

collection.queryIndexes().getAllIndexes()
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.