title: How to enable field data in elasticsearch
body: <p>I'm trying to enable field data in elasticsearch, but I'm still gettting the same error.
  Can anyone tell me what I'm missing?</p>
  
  <p><strong>.NET Code</strong></p>
  
  <pre><code>var resByApp = client.Search&lt;ApiCall&gt;(s =&gt; s.Aggregations(a =&gt; a
                      .Filter("my_filter", f =&gt; f
                            .Filter(fd =&gt; fd
                                 .DateRange(r =&gt; r
                                     .GreaterThan(DateTime.UtcNow.ToBeginOfDay().AddDays(-DefaultDaysRange))
                                     .Field(p =&gt; p.CreatedDate)
                                 )
                                 &amp;&amp;
                                 fd.Term(t =&gt; t.ServiceId, serviceId)
                             )
                      .Aggregations(ag =&gt; ag
                                .Terms("app_agg", st =&gt; st
                                    .Field(af =&gt; af.AppId))
                                )
                            )));
  </code></pre>
  
  <p><strong>DebugInformation:</strong></p>
  
  <pre><code>Invalid NEST response built from a unsuccessful low level call on POST: /abc_apicalls/apicall/_search
  # Audit trail of this API call:
   - [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:00.0459990
  # ServerError: ServerError: 400Type: search_phase_execution_exception Reason: "all shards failed" CausedBy: "Type: illegal_argument_exception Reason: "Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.""
  # OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request.
     at System.Net.HttpWebRequest.GetResponse()
     at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Users\russc\source\git\elasticsearch-net-5.x\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 164
  # Request:
  {"aggs":{"my_filter":{"filter":{"bool":{"must":[{"range":{"createdDate":{"gt":"2017-03-26T00:00:00"}}},{"term":{"serviceId":{"value":2}}}]}},"aggs":{"app_agg":{"terms":{"field":"appId"}}}}}}
  # Response:
  {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"abc_apicalls","node":"oYXnz0dhTZ6Bs5ZpspH1hg","reason":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [appId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."}},"status":400}
  </code></pre>
  
  <p><strong>What I tried:</strong></p>
  
  <pre><code>PUT abc_apicalls/apicall/text
  {
    "properties": {
      "appId": { 
        "type":     "text",
        "fielddata": true
      }
    }
  }
  </code></pre>
  
  <p><strong>This is the results for <code>GET abc_apicalls</code></strong></p>
  
  <pre><code>{
    "abc_apicalls": {
      "aliases": {},
      "mappings": {
        "apicall": {
          "properties": {
            "appId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "properties": {
              "properties": {
                "appId": {
                  "properties": {
                    "fielddata": {
                      "type": "boolean"
                    },
                    "type": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "type": "keyword",
                          "ignore_above": 256
                        }
                      }
                    }
                  }
                }
              }
            },
      ...
    }
  }
  </code></pre>
  
  <p>Resources: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html</a></p>