Robert Zaremba
Robert Zaremba

Reputation: 8481

How to create multiple indexes at once in RethinkDB?

In RethinkDB, is it possible to create multiple indexes at once?
Something like (which doesn't work):

r.db('test').table('user').indexCreate('name').indexCreate('email').run(conn, callback)

Upvotes: 1

Views: 319

Answers (1)

Joe Doliner
Joe Doliner

Reputation: 2230

Index creation is a fairly heavyweight operation because it requires scanning the existing documents to bring the index up to date. It's theoretically possible to allow creation of 2 indexes at the same time such that they both perform this process in parallel and halve the work We don't support that right now though.

However I suspect that's not what you're asking about. If you're just looking for a way to not have to wait for the index to complete and then come back and start the next one the best way would be to do:

table.index_create("foo").run(noreply=True)
# returns immediately
table.index_create("bar").run(noreply=True)
# returns immediately

You also can always do any number of writes in a single query by putting them in an array like so:

r.expr([table.index_create("foo"), table.index_create("bar")]).run()

I can't actually think of why this would be useful for index creation because index writes don't block until the index is ready but hey who knows. It's definitely useful in table creation.

Upvotes: 1

Related Questions