Rahul Singhai
Rahul Singhai

Reputation: 1339

Disabling analyzing of fields not present in index template

Can I combine dynamic_templates with index templates? We have defined index templates that apply to indices created with a prefix. For example following index template will create a mapping to any index starting with "te":

PUT /_template/template_1
{
  "template": "te*",
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "type1": {
      "_source": {
        "enabled": false
      },
      "_all": {
        "enabled": false
      },
      "properties": {
        "host_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z YYYY"
        }
      }
    }
  }
}

I also want to combine dynamic_template kind of functionality, so if any new "string" field comes in the data, its analysis gets disabled by default.

Upvotes: 0

Views: 76

Answers (1)

keety
keety

Reputation: 17441

Should be able to specify the dynamic mapping in the index template

Example:

 {
      "template": "te*",
      "settings": {
        "number_of_shards": 1
      },
      "mappings": {
        "type1": {
          "_source": {
            "enabled": false
          },
          "_all": {
            "enabled": false
          },
          "properties": {
            "host_name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "created_at": {
              "type": "date",
              "format": "EEE MMM dd HH:mm:ss Z YYYY"
            }
          },
          "dynamic_templates": [

            {
              "strings": {
                "match_mapping_type": "string",
                "mapping": {
                  "type": "string",
                  "index":"not_analyzed"
                }
              }
            }
          ]
        }
      }
    }

The above example would ensure any dynamic "string type" field for type1 would be unanalyzed.

Upvotes: 1

Related Questions