All Products
Document Center

OpenSearch:kvpairs clause

Last Updated:Feb 28, 2024


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.



  • 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 (,).


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.


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.