query

fun query(statement: String, common: CommonOptions = CommonOptions.Default, parameters: QueryParameters = QueryParameters.None, serializer: JsonSerializer? = null, consistency: QueryScanConsistency = QueryScanConsistency.notBounded(), readonly: Boolean = false, adhoc: Boolean = true, flexIndex: Boolean = false, metrics: Boolean = false, profile: QueryProfile = QueryProfile.OFF, maxParallelism: Int? = null, scanCap: Int? = null, pipelineBatch: Int? = null, pipelineCap: Int? = null, clientContextId: String? = UUID.randomUUID().toString(), raw: Map<String, Any?> = emptyMap()): Flow<QueryFlowItem>

Returns a Flow which may be collected to execute a scope-level N1QL query and process the results.

The returned Flow is cold, meaning the query is not executed unless the Flow is collected. If you collect the flow multiple times, the query is executed each time.

The extension function Flow<QueryFlowItem>.execute() may be used when when the results are known to fit in memory. It simply collects the flow into a QueryResult.

For larger query results, prefer the streaming version which takes a lambda to invoke when each row is received from the server: Flow<QueryFlowItem>.execute { row -> ... }.

Parameters

statement

the N1QL statement to execute.

common

options common to all requests.

parameters

parameters to the N1QL statement.

serializer

the serializer to use for converting parameters to JSON, and the default serializer for parsing QueryRow content. Defaults to the serializer configured on the cluster environment.

consistency

required if you want to read your own writes. Values other than QueryScanConsistency.notBounded tell the server to wait for the indexer to catch up with a certain state of the K/V service before executing the query.

readonly

pass true if the N1QL statement does not modify documents. This allows the client to retry the query if necessary.

adhoc

pass false if this is a commonly used query that should be turned into a prepared statement for faster execution.

flexIndex

pass true to use a full-text index instead of a query index.

metrics

pass true to include metrics in the response (access via QueryMetadata.metrics). Relatively inexpensive, and may be enabled in production with minimal impact.

profile

specifies how much profiling information to include in the response (access via QueryMetadata.profile). Profiling is relatively expensive, and can impact the performance of the server query engine. Not recommended for use in production, unless you're diagnosing a specific issue.

maxParallelism

Specifies the maximum parallelism for the query.

scanCap

Maximum buffered channel size between the indexer client and the query service for index scans. This parameter controls when to use scan backfill. Use 0 or a negative number to disable. Smaller values reduce GC, while larger values reduce indexer backfill.

pipelineBatch

Controls the number of items execution operators can batch for Fetch from the KV.

pipelineCap

Maximum number of items each execution operator can buffer between various operators.

clientContextId

an arbitrary string that identifies this query for diagnostic purposes.

raw

an "escape hatch" for passing arbitrary query options that aren't otherwise exposed by this method.