Getting java.lang.RuntimeException: java.util.concurrent.TimeoutException error while creating primary index

This is the line of code, I am using :-

@Grab(‘com.couchbase.client:java-client:2.2.7’)

//2.2.6
import java.util.concurrent.CountDownLatch;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlQueryRow;
import com.couchbase.client.java.query.SimpleN1qlQuery;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().connectTimeout(20000).build();
def cluster = CouchbaseCluster.create(env, ip_Address);
def bucket = cluster.openBucket(bucket_name, bucket_password);
log.info “Connection done”

String queryString = "CREATE PRIMARY INDEX primInd ON demo"

SimpleN1qlQuery simpleQuery = N1qlQuery.simple(queryString);
N1qlQueryResult resultSet = bucket.query(simpleQuery);

log.info “Primary index created”

It gives above error at this line - N1qlQueryResult resultSet = bucket.query(simpleQuery);

Could you please help to replicate the issue?

@simonbasle - Could you please help me on this… Its getting critical for me.

@avidCoder (note I don’t work at Couchbase anymore)
index creation can take quite some time, looks like it takes more than the default timeout on blocking operations. you might want to look at the async() version and provide a larger timeout yourself.

Ok Simon, Thanks… I’ll try providing larger timeout and using async() version

Even better might be to use the defer_build if you’re doing several of these. Doing an index build requires visiting all of the data. See the docs for how to add defer_build to your index creation.

And thanks @simonbasle!