2
我想輸出彈性搜索每個結果的分數。但是我不確定我怎麼能得到這個。c#彈性搜索nest如何輸出文檔分數
下面是我運行一個查詢當前代碼:
var searchResults = client.Search<Place>(s => s
.From(0)
.Size(5)
.Explain(true)
.TrackScores(true)
.Query(q => q
.QueryString(fqqs1 => fqqs1
.OnFieldsWithBoost(d => d
.Add("name", 5.0)
)
.Query("west midlands birmingham")
)
)
.Sort(sort => sort.OnField("_score").Descending())
.Sort(sort => sort.OnField(f => f.id).Ascending())
);
// Output the results to console
Console.WriteLine("\nTotal Hits: " + searchResults.HitsMetaData.Hits.Count + " out of " + searchResults.HitsMetaData.Total);
List<Result> results = new List<Result>();
foreach (Place result in searchResults.Documents)
{
results.Add(new Result
{
woeid = Convert.ToInt32(result.id),
name = result.name,
admin1 = result.admin1,
admin2 = result.admin2,
type = result.type
});
Console.WriteLine(result.id + " > " + result.name + " > " + result.admin1 + " > " + result.admin2 + " > " + result.type);
}