ES Custom Index Template

1. Official Website

1.1 template only when you create the index. Change the template has no effect on the existing index.

1.2 create index API higher priority than the priority of the template.

 

2. Specific examples:

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

Define a template named template_1, the template model for te *. Setting and mapping will be applied to any index name and te * template matching.

 

verification:

1. Create an index name for the test:

PUT /test

2. Get the test, template to create the index successfully.
GET / test

{
  "test" : {
    "aliases" : { },
    "mappings" : {
      "type1" : {
        "_source" : {
          "enabled" : false
        },
        "properties" : {
          "created_at" : {
            "type" : "date",
            "format" : "EEE MMM dd HH:mm:ss Z YYYY"
          },
          "host_name" : {
            "type" : "keyword"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1575360509771",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "L7tWIlj7Ty6VcKC7JdvLiA",
        "version" : {
          "created" : "6060099"
        },
        "provided_name" : "test"
      }
    }
  }
}

 

3. Create an index template contains aliases

PUT _template/template_2
{
    "template" : "te*",
    "settings" : {
        "number_of_shards" : 1
    },
    "aliases" : {
        "alias1" : {},
        "alias2" : {
            "filter" : {
                "term" : {"user" : "kimchy" }
            },
            "routing" : "kimchy"
        },
        "{index}-alias" : {} 
    }
}

{Index} placeholder will be replaced with the template to create the index at the actual index name

 

4. Delete the index template:

delete  /_template/template_1

5. Obtain all Index Template

GET /_template

5.2. Gets the index template wildcard matching

GET /_template/te*

6. Does the index template exists

HEAD /_template/template_1

7. The plurality of templates may index an index matching, in this case, are set and mapping incorporated into the final configuration index in. You may be used sequentially combined control order parameter , the first application of a lower order, and then covering them with a higher order. The same order value,

The result of the merger uncertain.

PUT /_template/template_1
{
    "index_patterns" : ["*"],
    "order" : 0,
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false }
        }
    }
}

PUT /_template/template_2
{
    "index_patterns" : ["te*"],
    "order" : 1,
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : true }
        }
    }
}

For example, test the index _source still enabled, behind the front cover, the mechanism to do this is to add / cover on high-end templates, and low-level template provides a basis.

8. Add the template version number:

PUT /_template/template_1
{
    "index_patterns" : ["*"],
    "order" : 0,
    "settings" : {
        "number_of_shards" : 1
    },
    "version": 123
}

9. Obtain the version number of the template:

GET /_template/template_1?filter_path=*.version

 

 

 

Guess you like

Origin www.cnblogs.com/glblog/p/11976518.html