Force waiting for indexes to be build before running a query

I’m using Couchbase server 4.5.1 with the node.js SDK. I’m also using couchbase-promises.

When the application start, it first check if all indexes are created and ready. If one or many are missing or are in deferred mode it create and/or build it.

Once the query BUILD INDEX has been terminated, it start running queries that will use those indexes. But when the first query is sent to the server, indexes are still in building state and an error message is being thrown:

No index available for join term event

I tried to use the consistency attribute, with REQUEST_PLUS or STATEMENT_PLUS but neither the first nor the second one resolved my issue.

Here is my code to run a query:

const query = async function(bucket, statement, params) {
  const q = N1qlQuery.fromString(statement).consistency(N1qlQuery.Consistency.STATEMENT_PLUS);
  return await bucket.queryAsync(q, params);

And it correctly run once all indexes are built.

How can I force the query to wait until all indexes are being correctly built? Or at least to wait for the indexes it must use?


Consistency is for index scan only not for index creation or build.

Check state of index using

select * from system:indexes;

Hi, yes I know how to check the state of indexes but is their any callback to tell me when a state change? Maybe I should run a live query on this? (Not sure LiveQuery is the exact term here, I’m used of Couchbase Lite).

There is no callback in the N1QL. Not sure about node JS @avsej

At the moment, there is no event interface from the cluster for this, so it’s not possible to register a callback/promise for this kind of thing. You should be able to pretty efficiently approximate it by polling for the index completion.

I finally managed to be sure all required indexes are built before running queries by querying select * from system:indexes every x seconds (I’m still trying to figure out what is the best ‘retry-delay’) and checking the state of those indexes.

Thank’s for support.