title: NEST Sort by Text field
body: <p>I am trying to write a search module that uses NEST and keeps the search functionality within its own bounded context.</p>
  
  <p>To achieve this, I have the following user profile search:</p>
  
  <pre><code>public class UserProfileSearch : IUserProfileSearch
  {
      ...
  
      public async Task&lt;PagedItems&lt;UserProfileModel&gt;&gt; FindAsync(string searchTerm, int skip, int take)
      {
          var client = _elasticClientProvider.GetClient();
          var response = await client.SearchAsync&lt;ElasticUserProfileModel&gt;(s =&gt; s
              .Index(_elasticConfiguration.GetIndex())
              .From(skip).Size(take)
              .Query(q =&gt; q.MultiMatch(m =&gt; m.Fields(f =&gt; f
                  .Field(u =&gt; u.Email)
                  .Field(u =&gt; u.FirstName)
                  .Field(u =&gt; u.LastName))
                  .Query(searchTerm)))
              .Sort(q =&gt; q.Ascending(u =&gt; u.Email)));
          var count = await client.CountAsync&lt;ElasticUserProfileModel&gt;(s =&gt; s.Index(_elasticConfiguration.GetIndex()));
          return new PagedItems&lt;UserProfileModel&gt; { Items = response.Documents.Cast&lt;UserProfileModel&gt;().ToArray(), Total = count.Count };
      }
  }
  </code></pre>
  
  <p>The response is failing consistently with this report:</p>
  
  <blockquote>
    <p>{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata
    is disabled on text fields by default. Set fielddata=true on [email]
    in order to load fielddata in memory by uninverting the inverted
    index. Note that this can however use significant memory.
    Alternatively use a keyword field
    instead."}],"type":"search_phase_execution_exception","reason":"all
    shards
    failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"xxxx","node":"xxxx","reason":{"type":"illegal_argument_exception","reason":"Fielddata
    is disabled on text fields by default. Set fielddata=true on [email]
    in order to load fielddata in memory by uninverting the inverted
    index. Note that this can however use significant memory.
    Alternatively use a keyword field instead."}}]},"status":400}</p>
  </blockquote>
  
  <p>However, I have done what was recommended in the report, but the same error keeps happening. I have defined</p>
  
  <pre><code>public class ElasticUserProfileModel : UserProfileModel
  {
      [Text(Fielddata = true)] public override string Email { get =&gt; base.Email; set =&gt; base.Email = value; }
  }
  </code></pre>
  
  <p>which should be exactly what the report is asking for. I am rebuilding the index with the <code>ElasticUserProfileModel</code> during each end-to-end test.</p>
  
  <p>I have also tried using the <code>Keyword</code> attribute rather than the <code>Text</code> attribute, but that is generating exactly the same error.</p>
  
  <p>If I sort by <code>Id</code> (which is numeric) instead of <code>Email</code>, there is no error. But this is a significantly less useful search.</p>
  
  <p>Is there a simple way to fix this?</p>