PumpkinSeed
PumpkinSeed

Reputation: 3113

Couchbase cluster's SearchQuery not working on Go client's v2 version

What I'm trying to do is performing a search against one of the buckets. I initialized the cluster with the bare minimum configuration, also set the ramsize of FTS and I added the FTS to services. Then I connected to the cluster with the minimum options:

cluster, err = gocb.Connect(settings.CouchbaseConnectionString, gocb.ClusterOptions{
    Username: settings.CouchbaseUser,
    Password: settings.CouchbasePassword,
})

Then I wanted to do the search as follow (at this point doesn't matter the query):

rows, err := cluster.SearchQuery("fts_index", query, nil)
if err != nil {
    log.Printf("View query error: %s\n", err)
    return 0
}

The result:

View query error: failed to get query provider: the cluster does not support cluster-level queries (only Couchbase Server 6.5 and later) and no bucket is open. If an older Couchbase Server version is used, at least one bucket needs to be opened...

That's explains what the actual issue is, but when I open a bucket right before the operation, that will throw the following error:

View query error: failed to get query provider: not connected to cluster...

I debuged the code, and the Query checks for GCCCP polling, so when the bucket's not opened the field of the cluster's clusterClient set to a value, so the GCCCP support can read it, but it's tells that not supported so throws me the first error. After I open the bucket the cluster's clusterClient set to nil and because of this throws me the second error.

Any idea how can I perform a serach?

Versions:

Upvotes: 1

Views: 1562

Answers (2)

PumpkinSeed
PumpkinSeed

Reputation: 3113

I found a related issue, where I have to wait while the code connect to the cluster's bucket properly.

Solution:

bucket := cluster.Bucket("bucket")
bucket.WaitUntilReady(30*time.Second, &gocb.WaitUntilReadyOptions{DesiredState: gocb.ClusterStateOnline})
rows, err := cluster.SearchQuery("fts_index", query, nil)
// ...

The important part is the WaitUntilReady.

Upvotes: 2

Cyrus
Cyrus

Reputation: 1

It looks like you need to open bucket first as described on https://docs.couchbase.com/go-sdk/current/hello-world/start-using-sdk.html

Upvotes: 0

Related Questions