All Products
Search
Document Center

OpenSearch:Fine sort functions

Last Updated:Apr 01, 2026

Fine sort expressions score the candidates from rough sort and return the highest-ranking results. Define custom sort expressions per application and pass them in search queries to control how results are ranked. Sort expressions support basic operations (arithmetic, relational, logical, bitwise, and conditional), mathematical functions, and the feature functions described on this page.

Note

Basic operations—arithmetic, relational, logical, and conditional—require numbers or field values of the NUMERIC type. Most function-based operations cannot be applied to values of the STRING type.

Text relevance

Use text relevance functions to measure how closely a document's content matches the search query.

FunctionWhat it returns
text_relevanceText relevance score between the search query and a field value
field_match_ratioRatio of matched terms in a field to the total number of terms in that field
query_match_ratioRatio of query terms that hit a specific field to the total number of terms in the search query
fieldterm_proximityProximity of matched terms within a field
field_lengthNumber of terms in a field
query_term_countNumber of terms in the search query after analysis
query_term_match_countNumber of query terms that hit a specific field in a document
field_term_match_countNumber of terms in a field that match the search query
query_min_slide_windowRatio of query terms that hit a specific field to the minimum window that contains those terms in the field

Geographical location relevance

Use geo functions to score documents by proximity to a reference point. The three decay functions (gauss_decay, linear_decay, exp_decay) share the same underlying concept—they calculate a score that decreases as values move further from a specified origin—but differ in the shape of the decay curve (Gaussian bell curve, linear, or exponential). Choose the curve that best matches how steeply you want scores to drop with distance.

FunctionWhat it returns
distanceSpherical distance between two geographic points; commonly used in location-based service (LBS) scenarios
gauss_decayDecay score using a Gaussian (bell curve) function based on distance from a specified origin
linear_decayDecay score using a linear function based on distance from a specified origin
exp_decayDecay score using an exponential function based on distance from a specified origin

Timeliness

Use timeliness functions to score documents by how recently they were created or updated. Choose the unit based on the time precision your application requires.

FunctionWhat it returns
timelinessTimeliness score indicating document freshness, in seconds
timeliness_msTimeliness score indicating document freshness, in milliseconds

Functionality

Use these functions for specific ranking tasks: tag-based scoring, score passthrough from rough sort, query parameter extraction, score normalization, and set membership checks.

FunctionWhat it returns
tag_matchScore based on matching query clauses against document tags, weighted by matched tag weights
first_phase_scoreScore calculated by the rough sort expression
kvpairs_valueValue of a specified field from a kvpairs clause in the query
normalizeScore normalized from its original value range to [0,1]
in or notinWhether a field value is in (or not in) a specified list

What's next