Collection Query Index Manager
Samples
import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.Collection
import kotlin.time.Duration.Companion.minutes
fun main() {
//sampleStart
// Create a new primary index on a collection
collection.queryIndexes.createPrimaryIndex()
//sampleEnd
}
import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.Collection
import kotlin.time.Duration.Companion.minutes
fun main() {
//sampleStart
// Get all indexes in bucket
val allCollections = bucket.collections.getAllScopes()
.flatMap { it.collections }
.map { bucket.scope(it.scopeName).collection(it.name) }
val allIndexesInBucket = allCollections
.flatMap { it.queryIndexes.getAllIndexes() }
allIndexesInBucket.forEach { println(it) }
//sampleEnd
}
import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.Collection
import kotlin.time.Duration.Companion.minutes
fun main() {
//sampleStart
// Create deferred indexes, build them, and wait for them to come online
with(collection.queryIndexes) {
// create a deferred index
createPrimaryIndex(deferred = true)
// build all deferred indexes in a collection
buildDeferredIndexes()
// wait for build to complete
watchIndexes(
timeout = 1.minutes,
indexNames = emptySet(),
includePrimary = true,
)
}
//sampleEnd
}
Functions
Link copied to clipboard
suspend fun buildDeferredIndexes(common: CommonOptions = CommonOptions.Default)
Content copied to clipboard
Builds any deferred indexes in this collection.
Link copied to clipboard
suspend fun createIndex(indexName: String, fields: Collection<String>, common: CommonOptions = CommonOptions.Default, ignoreIfExists: Boolean = false, deferred: Boolean = false, numReplicas: Int? = null, with: Map<String, Any?> = emptyMap())
Content copied to clipboard
Creates a secondary index.
Link copied to clipboard
suspend fun createPrimaryIndex(common: CommonOptions = CommonOptions.Default, indexName: String? = null, ignoreIfExists: Boolean = false, deferred: Boolean = false, numReplicas: Int? = null, with: Map<String, Any?> = emptyMap())
Content copied to clipboard
Creates a primary index (an index on all keys in the collection).
Link copied to clipboard
suspend fun dropPrimaryIndex(common: CommonOptions = CommonOptions.Default, ignoreIfNotExists: Boolean = false)
Content copied to clipboard
Drops an anonymous primary index on this collection.
Link copied to clipboard
suspend fun getAllIndexes(common: CommonOptions = CommonOptions.Default): List<QueryIndex>
Content copied to clipboard
Link copied to clipboard
suspend fun watchIndexes(indexNames: Collection<String>, includePrimary: Boolean = false, timeout: Duration, common: CommonOptions = CommonOptions.Default)
Content copied to clipboard
Returns when the indexes named indexNames in this collection are online.