We wrote a little tool that creates all indices we need before one of our microservice starts. We use Java SDK 2.7.
We first create all indices with defer_build
.
CREATE INDEX <name> ON <bucket>(<fields>) WHERE <condition> USING GSI WITH {"defer_build":true,"nodes":[<index nodes>]}]
Only after all indices are created we run the actual BUILD INDEX ...
and wait for completion.
As far as I learned, this is the recommended appoarch. Nonetheless, we get a lot of errors in the CREATE INDEX
step saying:
Create index cannot proceed due to rebalance in progress, another concurrent create index request, network partition, node failover, or indexer failure.
We got it working by adding a random delay and retrying the operation (sometimes up to 30 times).
Any recommendation on how to create multiple (in the order of 40) indices at the same time?