CollectionQueryIndexManager

class CollectionQueryIndexManager

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)

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())

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())

Creates a primary index (an index on all keys in the collection).

Link copied to clipboard
suspend fun dropIndex(indexName: String, common: CommonOptions = CommonOptions.Default, ignoreIfNotExists: Boolean = false)

Drops the primary or secondary index named indexName on this collection.

Link copied to clipboard
suspend fun dropPrimaryIndex(common: CommonOptions = CommonOptions.Default, ignoreIfNotExists: Boolean = false)

Drops an anonymous primary index on this collection.

Link copied to clipboard
suspend fun getAllIndexes(common: CommonOptions = CommonOptions.Default): List<QueryIndex>
Link copied to clipboard
suspend fun watchIndexes(indexNames: Collection<String>, includePrimary: Boolean = false, timeout: Duration, common: CommonOptions = CommonOptions.Default)

Returns when the indexes named indexNames in this collection are online.