title: Elasticsearch fielddata - should I use it?
body: <p>Given an index with documents that have a <em>brand</em> property, we need to create a term aggregation that is case insensitive.</p>
  
  <p><strong>Index definition</strong></p>
  
  <p>Please note that the use of <strong>fielddata</strong></p>
  
  <pre><code>PUT demo_products
  {
    "settings": {
      "analysis": {
        "analyzer": {
          "my_custom_analyzer": {
            "type": "custom",
            "tokenizer": "keyword",
            "filter": [
              "lowercase"
            ]
          }
        }
      }
    },
    "mappings": {
      "product": {
        "properties": {
          "brand": {
            "type": "text",
            "analyzer": "my_custom_analyzer",
            "fielddata": true,
          }
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Data</strong></p>
  
  <pre><code>POST demo_products/product
  {
    "brand": "New York Jets"
  }
  
  POST demo_products/product
  {
    "brand": "new york jets"
  }
  
  POST demo_products/product
  {
    "brand": "Washington Redskins"
  }
  </code></pre>
  
  <p><strong>Query</strong></p>
  
  <pre><code>GET demo_products/product/_search
  {
    "size": 0,
    "aggs": {
      "brand_facet": {
        "terms": {
          "field": "brand"
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>"aggregations": {
      "brand_facet": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": [
          {
            "key": "new york jets",
            "doc_count": 2
          },
          {
            "key": "washington redskins",
            "doc_count": 1
          }
        ]
      }
    }
  </code></pre>
  
  <p>If we use <code>keyword</code> instead of <code>text</code> we end up the 2 buckets for New York Jets because of the differences in casing.</p>
  
  <p>We're concerned about the performance implications by using fielddata. However if fielddata is disabled we get the dreaded <em>"Fielddata is disabled on text fields by default."</em></p>
  
  <p>Any other tips to resolve this - or should we not be so concerned about fielddate?</p>