Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Index Templates with Dynamic Templates

I would like to combine Index Templates and Dynamic Templates so that the dynamic mapping I define is automatically added to all indices created.

Is this possible?

Regards Morten

like image 446
mortenl Avatar asked Feb 07 '23 11:02

mortenl


2 Answers

In the index template define the mappings as dynamic template. For example :

PUT /_template/template_1
{
  "template": "yourindex*",
  "mappings": {
    "my_type": {
      "dynamic_templates": [
        {your dynamic templates ...}
      ]
    }
  }
}
like image 165
Hugodby Avatar answered Feb 12 '23 14:02

Hugodby


You can do something like this:

PUT /_template/my_template
{
  "template": "name-*",
  "mappings": {
    "my_type": {
      "dynamic_templates": [
        {
          "rule1": {
            "match": "field*",
            "mapping": {
              "type": "string",
              "index": "analyzed"
            }
          }
        },
        {
          "rule2": {
            "match": "another*",
            "mapping": {
              "type": "integer"
            }
          }
        }
      ],
      "properties": {
         "field": {
             "type": "string"
         }
      }
    }
  }
}
like image 27
Val Avatar answered Feb 12 '23 14:02

Val