# Sort string with NEST

**URL:** <https://discuss.elastic.co/t/sort-string-with-nest/180370>\
**Category:** Elasticsearch\
**Created:** [May 9, 2019, 1:09pm UTC](https://discuss.elastic.co/t/sort-string-with-nest/180370 "2019-05-09T13:09:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruben\_Baeza\_Colin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruben_baeza_colin/32/45902_2.png) [@Ruben\_Baeza\_Colin](https://discuss.elastic.co/u/Ruben_Baeza_Colin)\
**Post date:** [May 9, 2019, 1:09pm UTC](https://discuss.elastic.co/t/sort-string-with-nest/180370/1 "2019-05-09T13:09:34Z")

</div>

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

this is my code

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [May 13, 2019, 3:52pm UTC](https://discuss.elastic.co/t/sort-string-with-nest/180370/2 "2019-05-13T15:52:19Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html)?

---

<div class="post-metadata">

**Author:** ![Ruben\_Baeza\_Colin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruben_baeza_colin/32/45902_2.png) [@Ruben\_Baeza\_Colin](https://discuss.elastic.co/u/Ruben_Baeza_Colin)\
**Post date:** [May 13, 2019, 6:58pm UTC](https://discuss.elastic.co/t/sort-string-with-nest/180370/3 "2019-05-13T18:58:37Z")

</div>

Hi, thanks for help me

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

this is my code:

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

```

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 10, 2019, 6:58pm UTC](https://discuss.elastic.co/t/sort-string-with-nest/180370/4 "2019-06-10T18:58:37Z")

</div>

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