Class QueryOptions

    • Constructor Detail

      • QueryOptions

        protected QueryOptions()
        The options should only be instantiated through the queryOptions() static method.
    • Method Detail

      • raw

        public QueryOptions raw​(String key,
                                Object value)
        Allows providing custom JSON key/value pairs for advanced usage.

        If available, it is recommended to use the methods on this object to customize the query. This method should only be used if no such setter can be found (i.e. if an undocumented property should be set or you are using an older client and a new server-configuration property has been added to the cluster).

        Note that the value will be passed through a JSON encoder, so do not provide already encoded JSON as the value. If you want to pass objects or arrays, you can use JsonObject and JsonArray respectively.

        Parameters:
        key - the parameter name (key of the JSON property) or empty.
        value - the parameter value (value of the JSON property).
        Returns:
        the same QueryOptions for chaining purposes.
      • adhoc

        public QueryOptions adhoc​(boolean adhoc)
        Allows turning this request into a prepared statement query.

        If set to

        false
        , the SDK will transparently perform "prepare and execute" logic the first time this query is seen and then subsequently reuse the prepared statement name when sending it to the server. If a query is executed frequently, this is a good way to speed it up since it will save the server the task of re-parsing and analyzing the query.

        If you are using prepared statements, make sure that if certain parts of the query string change you are using named or positional parameters. If the statement string itself changes it cannot be cached.

        Parameters:
        adhoc - if set to false this query will be turned into a prepared statement query.
        Returns:
        the same QueryOptions for chaining purposes.
      • scanConsistency

        public QueryOptions scanConsistency​(QueryScanConsistency scanConsistency)
        Customizes the consistency guarantees for this query.

        Tuning the scan consistency allows to trade data "freshness" for latency and vice versa. By default QueryScanConsistency.NOT_BOUNDED is used, which means that the server returns the data it has in the index right away. This is fast, but might not include the most recent mutations. If you want to include all the mutations up to the point of the query, use QueryScanConsistency.REQUEST_PLUS.

        Note that you cannot use this method and consistentWith(MutationState) at the same time, since they are mutually exclusive. As a rule of thumb, if you only care to be consistent with the mutation you just wrote on the same thread/app, use consistentWith(MutationState). If you need "global" scan consistency, use QueryScanConsistency.REQUEST_PLUS on this method.

        Parameters:
        scanConsistency - the index scan consistency to be used for this query.
        Returns:
        the same QueryOptions for chaining purposes.
      • serializer

        public QueryOptions serializer​(JsonSerializer serializer)
        Provides a custom JsonSerializer to be used for decoding the rows as they return from the server.

        If no serializer is provided, the default one from the ClusterEnvironment will be used (which is sufficient for most tasks at hand).

        Parameters:
        serializer - a custom serializer for this request.
        Returns:
        the same QueryOptions for chaining purposes.
      • profile

        public QueryOptions profile​(QueryProfile profile)
        Customizes the server profiling level for this query.

        Note that you only want to tune this if you want to gather profiling/performance metrics for debugging. Turning this on in production (depending on the level) will likely have performance impact on the server query engine as a whole and on this query in particular!

        Parameters:
        profile - the custom query profile level for this query.
        Returns:
        the same QueryOptions for chaining purposes.
      • clientContextId

        public QueryOptions clientContextId​(String clientContextId)
        Supports providing a custom client context ID for this query.

        If no client context ID is provided by the user, a UUID is generated and sent automatically so by default it is always possible to identify a query when debugging. If you do not want to send one, pass either null or an empty string to this method.

        Parameters:
        clientContextId - the client context ID - if null or empty it will not be sent.
        Returns:
        the same QueryOptions for chaining purposes.
      • metrics

        public QueryOptions metrics​(boolean metrics)
        Enables per-request metrics in the trailing section of the query.

        If this method is set to true, the server will send metrics back to the client which are available through the QueryMetaData.metrics() section. As opposed to profile(QueryProfile), returning metrics is rather cheap and can also be enabled in production if needed.

        Parameters:
        metrics - set to true if the server should return simple query metrics.
        Returns:
        the same QueryOptions for chaining purposes.
      • scanWait

        public QueryOptions scanWait​(Duration wait)
        Allows customizing how long the query engine is willing to wait until the index catches up to whatever scan consistency is asked for in this query.

        Note that if QueryScanConsistency.NOT_BOUNDED is used, this method doesn't do anything at all. If no value is provided to this method, the server default is used.

        Parameters:
        wait - the maximum duration the query engine is willing to wait before failing.
        Returns:
        the same QueryOptions for chaining purposes.
      • maxParallelism

        public QueryOptions maxParallelism​(int maxParallelism)
        Allows overriding the default maximum parallelism for the query execution on the server side.

        If 0 or a negative value is set, the parallelism is disabled. If not provided, the server default will be used.

        Parameters:
        maxParallelism - the maximum parallelism for this query, 0 or negative values disable it.
        Returns:
        the same QueryOptions for chaining purposes.
      • readonly

        public QueryOptions readonly​(boolean readonly)
        Allows explicitly marking a query as being readonly and not mutating and documents on the server side.

        In addition to providing some security in that you are not accidentally modifying data, setting this flag to true also helps the client to more proactively retry and re-dispatch a query since then it can be sure it is idempotent. As a result, if your query is readonly then it is a good idea to set this flag.

        If set to true, then (at least) the following statements are not allowed:

        1. CREATE INDEX
        2. DROP INDEX
        3. INSERT
        4. MERGE
        5. UPDATE
        6. UPSERT
        7. DELETE
        Parameters:
        readonly - true if readonly should be set, false is the default and will use the server side default.
        Returns:
        the same QueryOptions for chaining purposes.
      • scanCap

        public QueryOptions scanCap​(int scanCap)
        Supports customizing the maximum buffered channel size between the indexer and the query service.

        This is an advanced API and should only be tuned with care. Use 0 or a negative number to disable.

        Parameters:
        scanCap - the scan cap size, use 0 or negative number to disable.
        Returns:
        the same QueryOptions for chaining purposes.
      • pipelineBatch

        public QueryOptions pipelineBatch​(int pipelineBatch)
        Supports customizing the number of items execution operators can batch for fetch from the KV layer on the server.

        This is an advanced API and should only be tuned with care.

        Parameters:
        pipelineBatch - the pipeline batch size.
        Returns:
        the same QueryOptions for chaining purposes.
      • pipelineCap

        public QueryOptions pipelineCap​(int pipelineCap)
        Allows customizing the maximum number of items each execution operator can buffer between various operators on the server.

        This is an advanced API and should only be tuned with care.

        Parameters:
        pipelineCap - the pipeline cap size.
        Returns:
        the same QueryOptions for chaining purposes.
      • parameters

        public QueryOptions parameters​(JsonObject named)
        Sets named parameters for this query.

        Note that named and positional parameters cannot be used at the same time. If one is set, the other one is "nulled" out and not being sent to the server.

        Parameters:
        named - JsonObject the named parameters.
        Returns:
        the same QueryOptions for chaining purposes.
      • parameters

        public QueryOptions parameters​(JsonArray positional)
        Sets positional parameters for this query.

        Note that named and positional parameters cannot be used at the same time. If one is set, the other one is "nulled" out and not being sent to the server.

        Parameters:
        positional - JsonArray the positional parameters.
        Returns:
        the same QueryOptions for chaining purposes.
      • flexIndex

        public QueryOptions flexIndex​(boolean flexIndex)
        Tells the query engine to use a flex index (utilizing the search service).
        Parameters:
        flexIndex - if a flex index should be used, false is the default.
        Returns:
        the same QueryOptions for chaining purposes.
      • preserveExpiry

        @SinceCouchbase("7.1")
        @Uncommitted
        public QueryOptions preserveExpiry​(boolean preserveExpiry)
        Tells the query engine to preserve expiration values set on any documents modified by this query.

        This feature works from Couchbase Server 7.1.0 onwards.

        Parameters:
        preserveExpiry - if expiration values should be preserved, the default is false.
        Returns:
        the same QueryOptions for chaining purposes.