ELK

18.Elasticsearch索引模板-2

2022-04-14  本文已影响0人  大勇任卷舒

18.1 Simulate多组件模板

POST /_index_template/_simulate_index/te-000001
POST /_index_template/_simulate/template_1
PUT /_component_template/ct1
{
  "template": {
    "settings": {
      "index.number_of_shards": 2
    }
  }
}
PUT /_component_template/ct2
{
  "template": {
    "settings": {
      "index.number_of_replicas": 0
    },
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}
POST /_index_template/_simulate
{
  "index_patterns": ["my*"],
  "template": {
    "settings" : {
      "index.number_of_shards" : 3
    }
  },
  "composed_of": ["ct1", "ct2"]
}
{
  "template" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "3", 
        "number_of_replicas" : "0"
      }
    },
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date" 
        }
      }
    },
    "aliases" : { }
  },
  "overlapping" : [
    {
      "name" : "template_1", 
      "index_patterns" : [
        "my*"
      ] 
    }
  ] 
}

18.2 模板示例:保存到 Elasticsearch

{
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : "5s"
  },
  "mappings" : {
    "_default_" : {
      "_all" : {"enabled" : true},
      "dynamic_templates" : [ {
        "string_fields" : {
          "match" : "*",
          "match_mapping_type" : "string",
          "mapping" : {
            "type" : "string", "index" : "analyzed", "omit_norms" : true,
              "fields" : {
                "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256}
            } 
          }
        }
      } ],
      "properties" : {
        "@version": { "type": "string", "index": "not_analyzed" },
        "geoip" : {
          "type" : "object",
            "dynamic": true,
            "path": "full",
            "properties" : {
              "location" : { "type" : "geo_point" }
            } 
          } 
        } 
      }
    }
 }
ElasticsearchException[org.elasticsearch.common.breaker.CircuitBreakingException: Data too large, 
data for field [@timestamp] would be larger than limit of [639015321/609.4mb]]
{
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : "5s"
  },
  "mappings" : {
    "_default_" : {
      "_all" : {"enabled" : true},
      "dynamic_templates" : [ {
        "string_fields" : {
          "match" : "*",
          "match_mapping_type" : "string",
          "mapping" : {
            "type" : "string", "index" : "analyzed", "omit_norms" : true,
              "fields" : {
                "raw" : { "type": "string", "index" : "not_analyzed", "ignore_above" : 256, "doc_values": true }
              } 
            }
          }
        } ],
        "properties" : {
          "@version": { "type": "string", "index": "not_analyzed" },
          "@timestamp": { "type": "date", "index": "not_analyzed", "doc_values": true, "format": "dateOptionalTime" },
          "geoip" : {
            "type" : "object",
              "dynamic": true,
              "path": "full",
              "properties" : {
            "location" : { "type" : "geo_point" }
          } 
        } 
      } 
    }
  }
}
{
  "order" : 1,
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : 
"20s"
  }
}

大数据视频推荐:
腾讯课堂
CSDN
ELK入门精讲
AIOps智能运维实战
ELK7 stack开发运维
大数据语音推荐:
ELK7 stack开发运维
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通

上一篇 下一篇

猜你喜欢

热点阅读