I would like to output the score for each result from elastic search. But I'am unsure how I can get this.
Below is my current code for running a query:
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);
}
use the .Hits property collection on the ISearchResponse<T> - The collection contains the score for each document in the .Score property, as well as the document in the .Source property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With