IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Distance Feature Query Usage
editDistance Feature Query Usage
editBoosts 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 date
editAn instance of DateMath
can be provided as the origin
, with pivot
being a Time
from the origin
Fluent DSL example
editq .DistanceFeature(rf => rf .Boost(1.1) .Field(f => f.StartedOn) .Origin(DateMath.FromString("now")) .Pivot(new Time("7d")) )
Object Initializer syntax example
editnew 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 location
editYou 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 example
editq .DistanceFeature(rf => rf .Name("name") .Boost(1.1) .Field(f => f.LeadDeveloper.Location) .Origin(new GeoCoordinate(70, -70)) .Pivot(new Distance(100, DistanceUnit.Miles)) )
Object Initializer syntax example
editnew DistanceFeatureQuery() { Name = "name", 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": { "_name": "name", "boost": 1.1, "field": "leadDeveloper.location", "origin": [ -70.0, 70.0 ], "pivot": "100mi" } }