Sort string with NEST

I have a problem when use "sort" with a string field

this is my code

var sortClauses = new List<ISort>();

sortClauses.Add(new SortField { Field = "aBC", Order = SortOrder.Ascending });

but when I use decimal field I don´t have problems

var sortClauses = new List<ISort>();

sortClauses.Add(new SortField { Field = "precio", Order = SortOrder.Ascending });

I'm using elasticsearch 6.6 and NEST 6.6
thanks for your help

What sort of problem are you having? What error message/exception do you get? Are you possibly trying to sort on a text field that does not have fielddata enabled?

1 Like

Hi, thanks for help me

I read the fielddata is default disabled for text field, how can enable?

this is my code:

 public class ProductoResponse
    {
        public int Clave { get; set; }
        public string Nombre { get; set; }
        public string ABC { get; set; }
        public int Existencia { get; set; }
}

var mustClauses = new List<QueryContainer>();
var shouldClauses = new List<QueryContainer>();
var filterClauses = new List<QueryContainer>();
var sortClauses = new List<ISort>();

...

sortClauses.Add(new SortField { Field = "_score", Order = SortOrder.Descending });
sortClauses.Add(new SortField { Field = "aBC", Order = SortOrder.Ascending });
sortClauses.Add(new SortField { Field = "existencia", Order = SortOrder.Descending });
  
 var searchRequest = new SearchRequest<ProductoResponse>(Indices.All, Types.All)
   {
      Query = new BoolQuery {
          Must = mustClauses,
          Filter = filterClauses,
          Should = shouldClauses
      },
 Sort = sortClauses,
 From = 0,
 Size = 10
 };

var searchResponse = client.Search<ProductoResponse>(
                        searchRequest
                      );

Where can I enable fielddata?

thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.