All Products
Search
Document Center

OpenSearch:kvpairs clause

Last Updated:Feb 28, 2024

Description

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

kvpairs=key1:value1,key2:value2

  • key1 indicates a field and values1 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 (,).

Example:

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

You can use the following statement to query the documents that contain Alibaba based on the tags that are specified by the query_key parameter. The query_key parameter is of the INT_ARRAY type. The tags are created by using the following attribute values: key1=13, value1=10, key2=100, and value2=1. The tag_match function is used to check whether documents match the specified tags. If a document matches multiple tags, the tag that is assigned the largest value is used. The system calculates the number of documents that match the tags.

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

Usage notes

  • A kvpairs clause is optional.