1

I know that I can use dynamic_template to set string fields to not_analyzed for new fields in a specific new index.

Is there a way to have this setting applied globally - i.e. having the property not_analyzed set for any string field in any new index? (without the need to set it for each new index)

Community
  • 1
  • 1
WoJ
  • 27,165
  • 48
  • 180
  • 345

1 Answers1

9

Yes, you can achieve this by creating an index template on * with a _default_ mapping type and dynamic templates

curl -XPUT localhost:9200/_template/global -d '{
  "template": "*",
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ]
    }
  }
}'

Then you can create any document in any new index and the all string fields will be not_analyzed

curl -XPUT localhost:9200/dummy_index/dummy_type/1 -d '{"name": "dummy"}'

If you check the dummy_type mapping type of the newly created dummy_index, you'll see that the name field will be not_analyzed

Val
  • 207,596
  • 13
  • 358
  • 360