Function score query

Purpose

A function score query wraps an actual query, and contains a scoring function. The actual query yields documents. The function score query uses the scoring function to alter the score of each found document, altering the document order if document are ordered on score.

One purpose is to assign lower scores to older documents.

See also Elastic Search function score query.

Field doc_modified, other fields

The scoring function requires a field that supplies a value as function input. The field can be a date field, a numeric field, or a geo point. Field doc_modified could be used to supply a date value, or another field can be used.

Scoring function, decay function

Elastic Search supports several scoring function types, for example type script_score. Enterprise Search currently supports the decay function only. The decay function causes scores to be lower if at a greater distance from an origin. The origin could for example be "now", and at a distance/age of for example 100d the decay could be 0.5, causing the document score to be multiplied by 0.5.

Usage

Create a DecayScoringFunction using arguments as follows:

  • Field name, for example doc_modified. This field supplies the input value for the scoring function. If the field is not available in a document the function score will be 1.0.
  • Decay type, for example Exp. Supported types are the exponential decay, normal/gaussian decay, and linear decay.
  • Origin, for example "now". The distance is measured from this origin. For date fields it is possible to use date math expressions.
  • Scale, for example "100d". This is the rate of decay. The value indicates that at a distance of 100d a factor 0.5 is applied to the score, if 0.5 is the decay value and if the offset is 0.
  • Offset, for example "10d". This is the distance at which decaying starts. The value indicates that up to 10d no decay is applied, and 0.5 is applied at a distance of 110d.
  • Decay, for example 0.5. This indicates how documents are scored at a distance of offset + scale.

Set this function in an instance of class SearchQuery, using property ScoringFunction. Setting a scoring function  causes SearchQuery to create a FunctionScoreQuery that wraps the actual query and that applies the scoring function to the score of each document found by the actual query.

The decay is applied by multiplying the score by the decay. This is the Elastic Search boost mode multiply. Elastic Search includes other boost  modes, for example replace. This is currently not supported by Enterprise Search, which uses multiply by default.