Elasticsearch the index template

solved problem

  When the index type and configuration information are the same, you can use the index template to handle, otherwise we will manually create the index.

Creating Index Template

PUT _template/2019
{
  "index_patterns": ["20*", "product1*"],   
  "settings":{   
    "number_of_shards": 2,
    "number_of_replicas": 1
  },
  "mappings":{  
    "doc":{
      "properties":{
        "ip":{
          "type":"keyword " 
        }, 
        " Method, " : {
           " of the type " : " keyword " 
        } 
      } 
    } 
  } 
} 

# index_patterns is indexed mode, refer to when creating order when the index 20 and the beginning of the product1, using the index template 
# in settings setting, we custom index assignment for the three main fragments. copied unchanged slice 
# mappings specified mapping relationship

View Index Template

GET _cat/templates
GET _template
GET _template/2019
GET _template/20*

 

Use the index template

Add data and whether to use the query template

PUT 20190101/doc/1
{
  "ip": "127.0.0.1",
  "method":"GET"
}

PUT 20190102/doc/2
{
  "ip":"192.168.1.1",
  "method":"POST"
}

PUT product1_log/doc/1
{
  "ip":"127.0.0.1",
  "method":"GET"
}

GET 2019*/doc/_search
{
  "query": {
    "match_all": {}
  }
}

GET 20190101

 

Query results on the use of templates

{
  "20190101" : {
    "aliases" : { },
    "mappings" : {
      "doc" : {
        "properties" : {
          "ip" : {
            "type" : "keyword"
          },
          "method" : {
            "type" : "keyword"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1566821645952",
        "number_of_shards" : "2",
        "number_of_replicas" : "1",
        "uuid" : "Tzqx1mKvTmiBMfaOfhQAwg",
        "version" : {
          "created" : "6050499"
        },
        "provided_name" : "20190101"
      }
    }
  }
}  

Multi-template matching

PUT _template/2018_1
{
  "index_patterns": ["2018*"],
  "order":0,
  "settings":{
    "number_of_shards": 2
  }
}


PUT 2018010101/doc/1
{
  "method":"GET"
}
GET 2018010101/_settings

 

Remove Templates

DELETE _template/2018*

 

Guess you like

Origin www.cnblogs.com/Alexephor/p/11414741.html