How to solve "Fielddata is disabled on text fields by default"

Hi [again],

I already opened a while ago a Topic on this issue, but it expired. So I am opening a new one.

https://discuss.elastic.co/t/how-to-apply-mappings-just-once/181280

ElasticSearch 5.6.10

When I try to sort in Kibana a given field from data in ElasticSearch, I get the famous message "Fielddata is disabled on text fields by default". So I need to:

  1. convert that field for all existing indices
  2. make it that new indices, created daily, have already the right settings

I was pointed to https://www.elastic.co/guide/en/elasticsearch/reference/5.6/indices-templates.html

but I have to admit I don't fully understand it.
From what I have read in other parts of the documentation, it is not possible to modify existing indices. Right?

If not possible to get 1. and 2., then my priority is 2.
I have tried to apply a template for a fake index that does not exist yet, like this

 curl -X PUT "my.elasticsearch.host:9200/_template/template_1" -H 'Content-Type: application/json' -d'
{
  "template": "test*",
  "settings" : {
    "number_of_shards":1
  },
  "mappings": {
    "log": {
        "_source": {
          "enabled": false
        },
        "properties": {
          "user": {
            "type": "keyword"
          }
        }
    }
  }
}
'

and then tried to add a few documents to several indices:

curl -X PUT "my.elasticsearch.host:9200/test-1/log/1?pretty" -H 'Content-Type: application/json' -d '{ "user": "joe"}'
curl -X PUT "my.elasticsearch.host:9200/test-1/log/2?pretty" -H 'Content-Type: application/json' -d '{ "user": "jane"}'
curl -X PUT "my.elasticsearch.host:9200/test-2/log/1?pretty" -H 'Content-Type: application/json' -d '{ "user": "dan"}'
curl -X PUT "my.elasticsearch.host:9200/test-3/log/1?pretty" -H 'Content-Type: application/json' -d '{ "user": "mike"}'
curl -X PUT "my.elasticsearch.host:9200/test-3/log/2?pretty" -H 'Content-Type: application/json' -d '{ "user": "freddy"}'

However, that does not seem to work. When I query, I don't see the "user" in the output anywhere.
What am I missing?

OK... replying to myself. This template seems to do the trick for new documents.

curl -X PUT "my.elasticsearch.host:9200/_template/template_1" -H 'Content-Type: application/json' -d'
{
  "template": "test*",
  "mappings": {
     "log" : {
        "properties": {
          "user": {
            "type": "keyword"
        }
       }
    }
  }
}
'

Still don't know how to apply it to existing documents already stored. Maybe that is not possible.

Not possible but the “reindex” api will allow you to copy the old docs to an index with the correct mapping

thanks !!

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