All Products
Search
Document Center

OpenSearch:kvpairs clause

Last Updated:Apr 01, 2026

The kvpairs clause passes field values into the mutable part of a sort expression at query time, allowing you to supply values to specific feature functions via a query clause. Instead of hardcoding values in the sort expression, use kvpairs to supply them dynamically — keeping your sort logic flexible and reusable across queries.

Syntax

kvpairs=key1:value1,key2:value2,...
ComponentSeparatorDescription
key: (colon)The field name referenced in the sort expression
value: (colon)The value assigned to that field
Multiple pairs, (comma)Separate multiple key-value pairs with commas

Usage notes

  • The kvpairs clause is optional.

Examples

Pass a field to a distinct clause

Search for documents that contain "alibaba". Results are grouped by company_id — one document is returned per group, and the rest are discarded.

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

Pass match conditions to a feature function

Search for documents that contain "alibaba" using the match condition 13=10:100=1. The fine sort expression uses the tag_match function on an INT_ARRAY tag field. The tag field contains multiple attribute pairs.

The query_key in kvpairs holds the match condition string, which tag_match uses to evaluate attribute pairs in the tag field: values for matching attributes are summed, and the largest sum across all matched keys 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).