Index not found Exception after Altering Index

HI Team,

I have some indexes created for my application. I needed to alter an index and I have done that.

But couchbase sdk is giving me IndexNotFoundException.

com.couchbase.client.core.error.IndexNotFoundException: Index not found
        at com.couchbase.client.java.AsyncUtils.block(AsyncUtils.java:51)
        at com.couchbase.client.java.Cluster.query(Cluster.java:393)

I have restarted the couchbase server in local env and this issue is fixed.
But in a Prod environment, I may need to refresh the indexes without restarting.

I tried
BUILD INDEX ON BucketName (IndexName1, IndexName2, IndexName3)

Note: I am manually able to execute the same query in couchbase query editor without any issue .

It didnt work. can you tell me what are the other options available without restarting couchbase server?

Thanks in advance

Make sure the query is the same in your application as it is in the query editor. They use the same mechanism - if it works in one, it should work in the other.

Hi @Manzoor128 :
I understand that you are getting the IndexNotFoundException after you have altered the index.
Could you please let us know what were you trying to do when you got this error.

The logs show, you application is doing something with cluster.query()

but Some code snippet would help us understand it better

Thanks
Praneeth

Hi praneeth.

I was trying to execute a query using couchbase sdk. At that time sdk was throwing this exception.

Note: It got fixed after a few minutes by itself.

Need to know after altering an index , will couchbase pick it up instantly or can we run any command like this to build it immediately ? or any other way
BUILD INDEX ON BucketName (IndexName1, IndexName2, IndexName3)

Thanks,
Manzoor

“will couchbase pick it up instantly or can we run any command like this to build it immediately ?”

As you found out, the index is not immediately available. We run into the same thing in our unit tests that create an index and then use it. The test has to poll until the index is ready.

https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/createindex.html
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/build-index.html

Just to add to Michael,
After creating/altering the index, Apart from index, its would be nice to check if query service is also ready to run any queries.
You can use the ping API on the bucket to check the query service availability

https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/Bucket.html