0
votes

How to sort data using multiple filters in elastic search using NEST queries.

  1. I need to apply two fields lets say price and kilometer for cars in results set. I want the results sorted based on these fields by ASC or DESC.

  2. How to get top five results based on conditions or some filters.

Please provide some links if available.

1

1 Answers

1
votes

This should answer your questions:

 IEnumerable<string> searchableFields = new List<string>() { "price", "kilometer" };

 SearchDescriptor<T> descriptor = new SearchDescriptor<T>();
 descriptor = descriptor.Size(5).OnFields(searchableFields)
                .Sort(s => s.OnField("price").Descending().OnField("kilometer").Ascending());

 var result = client.Search<T>(body => descriptor);