D
D
Daeamon2017-08-21 15:15:36
ASP.NET
Daeamon, 2017-08-21 15:15:36

How to get _score value from ElasticSearch NEST?

elasticClient.Search<NewsForSearch>(s => s
                            .Index("newsindex")
                            .Type("newsforsearch")
                            .Query(qq =>
                            {
                                QueryContainer query = null;
                                //query &= q.Term(p => p.State, userInput.State.ToString());

                                if (!string.IsNullOrEmpty(forSearch))
                                    query &= qq.Raw("{\"multi_match\" : {\"query\":    \"" + forSearch + "\", \"fields\": [ \"title\", \"content\",\"description\",\"categoryName\",\"sourceName\",\"regionName\" ]}}");
                                // За последние 24 часа
                                query &= qq.DateRange(p => p.LessThanOrEquals(DateMath.Now).GreaterThan(DateMath.FromString(DateTime.Now.AddDays(-1).ToString())));
                                return query;
                            }).Sort(
                                ss =>
                                {
                                    SortDescriptor<NewsForSearch> Sorting = new SortDescriptor<NewsForSearch>();
                                    Sorting = Sorting.Descending("_score");
                                    return Sorting;
                                }
                            ));

I am making a selection of similar materials, I need the score parameter, how can I get it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daeamon, 2017-08-22
@Daeamon

double score = (double)currentMatches.Hits.ElementAt(i).Score;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question