Not able to create Index from Java client

I am using Java client 2.7.16, I am trying to create the index using java client below is the code snippet for the same.

String nQuery = CREATE INDEX ix_name ON bucket-name(name) WITH {“num_replica”: 1}; --> this comes dynamically
Bucket bucket = getBucket(instance);
N1qlQueryResult result = bucket.query(N1qlQuery.simple(nQuery));

It throws an exception "nested exception is java.lang.NoSuchMethodError: io.opentracing.Tracer$SpanBuilder.startActive(Z)Lio/opentracing/Scope;"

can you please help me solve this issue, I want to use bucket.query(N1qlQuery.simple(nQuery)); this method only to create index, as they query comes dynamically so I do not want to alter the query.

I tried with java client 3.0.0 version also but it throws error unable to parse the scheme exception.
below is the code snippet I used for 3.0.0 version

Cluster cluster = Cluster.connect(“http://” + instance.getCluster().getClusterAddress(), instance.getBucket().getUserid(),
new String(Base64.getDecoder().decode(instance.getBucket().getPassword()), StandardCharsets.UTF_8) );

                QueryResult queryResult = cluster.query(nQuery);

Please suggest me how can I create the index using java client with plain query like CREATE INDEX ix_name ON bucket-name(name)


Hi there,

If you use SDK 3.x then there is a Query Index management API that will enable you to create indexes.

cluster.queryIndexes().createPrimaryIndex(bucketName, CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions()

(And also createIndex(…), etc.)
Also in SDK3.x, the connection string does not need the prefix “http://”, so you should just use your CB Server IP/address.

Similarly, there is a createN1qlIndex() function on the bucketManager, in SDK 2.7.x that you could checkout if you want to stick to the old SDK.

Hope this helps,