createIndexInBackground

Defines an index and builds it on a thread of the database's own, returning at once.

val build = db.createIndexInBackground(IndexDefinition.inverted("$.team"))
db.query(Query.where(path("$.team") eq "analytics")).use { rows -> … } // works already
build.await()

The query above is answered correctly while the build is still running: the index covers the segments it has reached and every other segment is scanned, which is what an index built out of per-segment sidecars has always allowed. Calling this again with the same definition resumes a build that was cancelled or that a crash cut short.

close stops any build in flight, so a database that is closed mid-build is left with an index that is defined and partly covered — a state the engine already lives in.

Throws