QueryIndexManager

class QueryIndexManager

Samples

import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.Keyspace
import kotlin.time.Duration.Companion.minutes
fun main() { 
   //sampleStart 
   // Create a new primary index on the default collection
cluster.queryIndexes.createPrimaryIndex(
    keyspace = Keyspace("bucketName")
) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.Keyspace
import kotlin.time.Duration.Companion.minutes
fun main() { 
   //sampleStart 
   // Create a new primary index on a collection other than the default
cluster.queryIndexes.createPrimaryIndex(
    keyspace = Keyspace("bucketName", "scopeName", "collectionName")
) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.Keyspace
import kotlin.time.Duration.Companion.minutes
fun main() { 
   //sampleStart 
   // Get all indexes in bucket
val indexes = cluster.queryIndexes.getAllIndexes(
    keyspace = Keyspace("bucketName")
) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.Keyspace
import kotlin.time.Duration.Companion.minutes
fun main() { 
   //sampleStart 
   // Create deferred indexes, build them, and wait for them to come online
val keyspace = Keyspace("bucketName")
with(cluster.queryIndexes) {
    // create a deferred index
    createPrimaryIndex(keyspace, deferred = true)

    // build all deferred indexes in a keyspace
    buildDeferredIndexes(keyspace)

    // wait for build to complete
    watchIndexes(
        keyspace = keyspace,
        timeout = 1.minutes,
        indexNames = emptySet(),
        includePrimary = true,
    )
} 
   //sampleEnd
}

Functions

Link copied to clipboard
suspend fun buildDeferredIndexes(keyspace: Keyspace, common: CommonOptions = CommonOptions.Default)

Builds any deferred indexes in keyspace.

Link copied to clipboard
suspend fun createIndex(keyspace: Keyspace, 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(keyspace: Keyspace, 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 keyspace).

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

Drops the primary or secondary index named indexName on keyspace.

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

Drops an anonymous primary index on keyspace.

Link copied to clipboard
suspend fun getAllIndexes(keyspace: Keyspace, common: CommonOptions = CommonOptions.Default): List<QueryIndex>

Returns all indexes from the collection identified by keyspace.

suspend fun getAllIndexes(bucket: String, @SinceCouchbase(value = "7.0") scope: String? = null, @SinceCouchbase(value = "7.0") collection: String? = null, common: CommonOptions = CommonOptions.Default): List<QueryIndex>

Returns all indexes from a bucket, scope, or collection.

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

Returns when the indexes named indexNames in keyspace are online.