All Products
Search
Document Center

OpenSearch:kvpairs clause

Last Updated:Feb 23, 2023

Overview

You can use a kvpairs clause to assign values to fields that are referenced in the mutable part of a sort expression. This way, you can pass field values to specific feature functions by using a query clause.

Syntax

A kvpairs clause is in the following format: key1:value1,key2:value2...

  • key1 indicates a field and value1 indicates the value of the field. Separate the field and value in a key-value pair with a colon (:).

  • You can specify multiple key-value pairs as needed. Separate multiple key-value pairs with commas (,).

Usage notes

  • A kvpairs clause is optional.

Examples

Use the following query clause to search for documents that contain "alibaba". The retrieved documents are aggregated based on the company_id field. A total of one extraction is performed. In the extraction, one document is extracted. The remaining documents after the extraction are discarded and only the extracted document is returned.

query=default:'alibaba'&&distinct=dist_key:company_id,dist_count:1,dist_times:1,reserved:false&&kvpairs=duniqfield:company_id

Use the following query clause to search for documents that contain "alibaba" based on the match condition of 13=10:100=1. In this case, the tag_match function is used. The match condition takes effect on a tag field of the INT_ARRAY type. The tag field contains multiple attribute pairs. The values for the attributes that match a key are added together to generate a sum. If multiple keys are matched, the largest sum is retained.

query=default:'alibaba'&&kvpairs=query_key:13=10:100=1  //The fine sort expression is tag_match(query_key, tags, sum, max, true, true).