Hi All,
I am trying to create Collection and Index using Couchbase SDK but getting below exception,
What i am doing,
private String scope = "test"
private static final String CREATE_COLLECTION = "CREATE COLLECTION `%s`";
private static final String CREATE_INDEX = "CREATE PRIMARY INDEX `#%s_primary` ON `%s`.`%s`.`%s`";
public void createCollectionAndIndex(String table, String collection) {
String bucketName = getBucketName(table);
couchbase.getBucket(bucketName).scope(scope).query(String.format(CREATE_COLLECTION, collection));
creatIndex(collection, bucketName);
}
public void creatIndex(String collection, String bucketName) {
couchbase.getBucket(bucketName).scope(scope).query(String.format(CREATE_INDEX, collection, bucketName, scope, collection));
}
Calling above code two times
createCollectionAndIndex("table1", "collection1"); //bucket1.test.collection1
createCollectionAndIndex("table2", "collection2"); //bucket2.test.collection2
Getting below exception,
[Request processing failed; nested exception is com.couchbase.client.core.error.IndexFailureException: The server reported an issue with the underlying index {"completed":true,"coreId":"0x7e49712500000001","errors":[{"code":12003,"message":"Keyspace not found in CB datastore: default:bucket2.test.collection2"}],"idempotent":false,"lastDispatchedFrom":"xx.xx.xx.196:55949","lastDispatchedTo":"fxsmdap1d.nam.nsroot.net:8093","requestId":164,"requestType":"QueryRequest","retried":0,"service":{"bucket":"bucket2","operationId":"a0123663-1ff4-432d-8b4d-f19103dce94d","scope":"test","statement":"CREATE PRIMARY INDEX `#collection2_primary` ON `bucket2`.`test`.`collection2`","type":"query"},"timeoutMs":75000,"timings":{"dispatchMicros":20402,"totalDispatchMicros":20402,"totalMicros":56998}}] with root cause
com.couchbase.client.core.error.IndexFailureException: The server reported an issue with the underlying index
at com.couchbase.client.java.AsyncUtils.block(AsyncUtils.java:51) ~[java-client-3.2.0.jar:na]
at com.couchbase.client.java.Scope.query(Scope.java:164) ~[java-client-3.2.0.jar:na]
at com.couchbase.client.java.Scope.query(Scope.java:151) ~[java-client-3.2.0.jar:na]
First collection and index will create with no issue but for second its throwing exception …