# Fielddata is disabled on text fields by default when upgrading from 2.x to 5.1

**URL:** <https://discuss.elastic.co/t/fielddata-is-disabled-on-text-fields-by-default-when-upgrading-from-2-x-to-5-1/71901>\
**Category:** Elasticsearch\
**Created:** [January 17, 2017, 7:45pm UTC](https://discuss.elastic.co/t/fielddata-is-disabled-on-text-fields-by-default-when-upgrading-from-2-x-to-5-1/71901 "2017-01-17T19:45:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zetaab](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zetaab](https://discuss.elastic.co/u/zetaab)\
**Post date:** [January 17, 2017, 7:45pm UTC](https://discuss.elastic.co/t/fielddata-is-disabled-on-text-fields-by-default-when-upgrading-from-2-x-to-5-1/71901/1 "2017-01-17T19:45:45Z")

</div>

I have problem that I updated from elasticsearch 2.x to 5.1. However, some of my data does not work in newer elasticsearch because of this "Fielddata is disabled on text fields by default" [https://www.elastic.co/guide/en/elasticsearch/reference/5.1/fielddata.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/fielddata.html) before 2.x it was enabled it seems.

Is there way to enable fielddata automatically to text fields?

I tried code like this

```
curl -XPUT http://localhost:9200/_template/template_1 -d '
{
  "template": "*",
  "mappings": {
    "_default_": {
      "properties": {
        "fielddata-*": {
          "type": "text",
          "fielddata": true
        }
      }
    }
  }
}'

```

but it looks like elasticsearch does not understand wildcard there in field name. Temporary solution to this is that I am running python script every 30 minutes, scanning all indices and adding fielddata=true to fields which are new.

The problem is that I have string data like "this is cool" in elasticsearch.

```
curl -XPUT 'http://localhost:9200/example/exampleworking/1' -d '
{
    "myfield": "this is cool"
}'

```

when trying to aggregate that:

```
curl 'http://localhost:9200/example/_search?pretty=true' -d '
{
    "aggs": {
        "foobar": {
            "terms": {
                "field": "myfield"
            }
        }
    }   
}'

```

"Fielddata is disabled on text fields by default. Set fielddata=true on [myfield]"

that elasticsearch documentation suggest using .keyword instead of adding fielddata. However, that is not returning data what I want.

```
curl 'http://localhost:9200/example/_search?pretty=true' -d '
{
    "aggs": {
        "foobar": {
            "terms": {
                "field": "myfield.keyword"
            }
        }
    }   
}'

```

returns:

```
  "buckets" : [
    {
      "key" : "this is cool",
      "doc_count" : 1
    }
  ]

```

which is not correct. Then I add fielddata true and everything works:

```
curl -XPUT 'http://localhost:9200/example/_mapping/exampleworking' -d '
{
  "properties": {
        "myfield": {
            "type": "text",
            "fielddata": true
        }
    }
}'

```

and then aggregate

```
curl 'http://localhost:9200/example/_search?pretty=true' -d '
{
    "aggs": {
        "foobar": {
            "terms": {
                "field": "myfield"
            }
        }
    }   
}'

```

return correct result

```
  "buckets" : [
    {
      "key" : "cool",
      "doc_count" : 1
    },
    {
      "key" : "is",
      "doc_count" : 1
    },
    {
      "key" : "this",
      "doc_count" : 1
    }
  ]

```

How I can add this fielddata=true automatically to all indices to all text fields? Is that even possible? In elasticsearch 2.x this is working out of the box.

---

<div class="post-metadata">

**Author:** ![zetaab](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zetaab](https://discuss.elastic.co/u/zetaab)\
**Post date:** [January 17, 2017, 9:07pm UTC](https://discuss.elastic.co/t/fielddata-is-disabled-on-text-fields-by-default-when-upgrading-from-2-x-to-5-1/71901/2 "2017-01-17T21:07:18Z")

</div>

i will answer to myself

```auto
curl -XPUT http:/localhost:9200/_template/template_1 -d '
{
  "template": "*",
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "strings2": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "text",
              "fielddata": true
            }
          }
        }
      ]
    }
  }
}'

```

this is doing what i want. Now all indexes have default settings fielddata true

---

<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:** [February 14, 2017, 9:07pm UTC](https://discuss.elastic.co/t/fielddata-is-disabled-on-text-fields-by-default-when-upgrading-from-2-x-to-5-1/71901/3 "2017-02-14T21:07:34Z")

</div>

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