Rank Feature Query Usage

edit

The rank_feature query is a specialized query that only works on rank_feature fields and rank_features fields. Its goal is to boost the score of documents based on the values of numeric features. It is typically put in a should clause of a bool query so that its score is added to the score of the query.

Compared to using function_score or other ways to modify the score, this query has the benefit of being able to efficiently skip non-competitive hits when track_total_hits is not set to true. Speedups may be spectacular.

See the Elasticsearch documentation on rank feature query for more details.

Fluent DSL example

edit
q
.RankFeature(rf => rf
    .Name("named_query")
    .Boost(1.1)
    .Field(f => f.Rank)
    .Saturation()
)

Object Initializer syntax example

edit
new RankFeatureQuery()
{
    Name = "named_query",
    Boost = 1.1,
    Field = Infer.Field<Project>(f => f.Rank),
    Function = new RankFeatureSaturationFunction()
}

Example json output.

{
  "rank_feature": {
    "_name": "named_query",
    "boost": 1.1,
    "field": "rank",
    "saturation": {}
  }
}

Fluent DSL example

edit
q
.RankFeature(rf => rf
    .Name("named_query")
    .Boost(1.1)
    .Field(f => f.Rank)
)

Object Initializer syntax example

edit
new RankFeatureQuery
{
    Name = "named_query",
    Boost = 1.1,
    Field = Infer.Field<Project>(f => f.Rank),
}

Example json output.

{
  "rank_feature": {
    "_name": "named_query",
    "boost": 1.1,
    "field": "rank"
  }
}

Fluent DSL example

edit
q
.RankFeature(rf => rf
    .Name("named_query")
    .Boost(1.1)
    .Field(f => f.Rank)
    .Linear())

Object Initializer syntax example

edit
new RankFeatureQuery
{
    Name = "named_query",
    Boost = 1.1,
    Field = Infer.Field<Project>(f => f.Rank),
    Function = new RankFeatureLinearFunction()
}

Example json output.

{
  "rank_feature": {
    "_name": "named_query",
    "boost": 1.1,
    "field": "rank",
    "linear": {}
  }
}