I am using NEST(c#) to communicate with Elasticsearch. However the results are not based on hit score, how can I sort my results based on hit score and also i am getting only 10 records. Below is my code sample
var result = client.Search(q => q
.Index(IndexName)
.From(0)
.Type("post")
.Fields("title","message")
.Size(10)
.Query(fq1 => fq1
.QueryString(fqqs1 => fqqs1
.OnFieldsWithBoost(d => d
.Add("title", 7.0)
.Add("message", 5.0))
.Query(SearchQuery))));
my message
field will contain large text , is it possible to get only few lines around the search keyword from the message just like google search result
Hello to sort by the hitscore just use
var result = client.Search(q => q
.Index(IndexName)
.From(0)
.Type("post")
.Fields("title","message")
.TrackScores(true)
.Size(10)
.Query(fq1 => fq1
.QueryString(fqqs1 => fqqs1
.OnFieldsWithBoost(d => d
.Add("title", 7.0)
.Add("message", 5.0)
)
.Query(SearchQuery)
)
.Sort(sort => sort.OnField("_score").Descending())
);
To get more records just increase the number in the Size()
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