2016-07-02 7 views
0

Upgrade von NEST 1.6.2 auf 2.3.3.Was sind die äquivalenten Typen für FunctionScoreFunctionsDescriptor & FunctionScoreFunction in 2.3.3

Was sind die neuen Typen für FunctionScoreFunctionsDescriptor und FunctionScoreFunction in NEST 2.3.3?

Sind sie FunctionScoreFunctionsDescriptor ->ScoreFunctionsDescriptor und FunctionScoreFunction ->ScoreFunctionsDescriptor?

Wenn das der Fall ist, bauen wir ein var functionScores = new List<Func<ScoreFunctionsDescriptor<IndexData>, ScoreFunctionsDescriptor<Property>>>(), aber wie kommen wir dies

unten

var searchDescriptor = new SearchDescriptor<IndexData>() .Paged(pageable) .Query(q => q .FunctionScore(fs => fs.Functions(***How do we pass the functionScores***));

Können wir bauen es wie unten?

functionScores.ForEach(f => searchDescriptor.Query(q => q.FunctionScore(fc => fc.Functions(f))));

Antwort

1

function_score Die Abfrage kann entweder eine oder eine IEnumerable<IScoreFunction>Func<ScoreFunctionsDescriptor<T>, IPromise<IList<IScoreFunction>>> d.h. eine Funktion, die eine Punktzahl Deskriptors nimmt und gibt eine Liste von Funktionen. Ein ScoreFunctionsDescriptor<T> Geräte IPromise<IList<IScoreFunction>>

auf dieser Basis, wenn wir eine Reihe von Funktionen zusammen aggregieren wollen, können wir eine Reihe von Funktionen aggregieren über die ein ScoreFunctionsDescriptor<T> nehmen und geben ein ScoreFunctionsDescriptor<T>

public class Document 
{ 
    public string Name { get; set;} 
    public GeoLocation Location { get; set;} 
} 

var functions = new List<Func<ScoreFunctionsDescriptor<Document>, ScoreFunctionsDescriptor<Document>>> 
{ 
    s => s.FieldValueFactor(fvf => fvf 
     .Field(f => f.Name).Weight(3)), 
    s => s.ExponentialGeoLocation(geo => geo 
     .Field(f => f.Location) 
     .Offset("1km") 
     .Origin(new GeoLocation(-33.87189, 151.21623)) 
     .Scale("2km") 
    ) 
}; 

client.Search<Document>(s => s 
    .Query(q => q 
     .FunctionScore(fs => fs 
      .Functions(sc => functions.Aggregate(sc, (a,f) => f(a))) 
     ) 
    ) 
); 

das in diesem Beispiel Erträge

{ 
    "query": { 
    "function_score": { 
     "functions": [ 
     { 
      "field_value_factor": { 
      "field": "name" 
      }, 
      "weight": 3.0 
     }, 
     { 
      "exp": { 
      "location": { 
       "origin": { 
       "lat": -33.87189, 
       "lon": 151.21623 
       }, 
       "scale": "2.0km", 
       "offset": "1.0km" 
      } 
      } 
     } 
     ] 
    } 
    } 
}