Distance Feature Query Usageedit

Boosts the relevance score of documents closer to a provided origin date or point. For example, you can use this query to give more weight to documents closer to a certain date or location.

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

Using a dateedit

An instance of DateMath can be provided as the origin, with pivot being a Time from the origin

Fluent DSL exampleedit

q
.DistanceFeature(rf => rf
    .Boost(1.1)
    .Field(f => f.StartedOn)
    .Origin(DateMath.FromString("now"))
    .Pivot(new Time("7d"))
)

Object Initializer syntax exampleedit

new DistanceFeatureQuery
{
    Boost = 1.1,
    Field = Infer.Field<Project>(f => f.StartedOn),
    Origin = DateMath.FromString("now"),
    Pivot = new Time("7d")
}

Example json output. 

{
  "distance_feature": {
    "boost": 1.1,
    "field": "startedOn",
    "origin": "now",
    "pivot": "7d"
  }
}

Using a locationedit

You can use the distance_feature query to find the nearest neighbors to a location. You can also use the query in a bool search''s should filter to add boosted relevance scores to the bool query’s scores.

An instance of GeoCoordinate can be provided as the origin, with pivot being a Distance from the origin

Fluent DSL exampleedit

q
.DistanceFeature(rf => rf
    .Boost(1.1)
    .Field(f => f.LeadDeveloper.Location)
    .Origin(new GeoCoordinate(70, -70))
    .Pivot(new Distance(100, DistanceUnit.Miles))
)

Object Initializer syntax exampleedit

new DistanceFeatureQuery()
{
    Boost = 1.1,
    Field = Infer.Field<Project>(f => f.LeadDeveloper.Location),
    Origin = new GeoCoordinate(70, -70),
    Pivot = new Distance(100, DistanceUnit.Miles)
}

Example json output. 

{
  "distance_feature": {
    "boost": 1.1,
    "field": "leadDeveloper.location",
    "origin": [
      -70.0,
      70.0
    ],
    "pivot": "100mi"
  }
}