美文网首页ELK
18.Elasticsearch索引模板-2

18.Elasticsearch索引模板-2

作者: 大勇任卷舒 | 来源:发表于2022-04-14 17:13 被阅读0次

18.1 Simulate多组件模板

  • 由于模板不仅可以由多个组件模板组成,还可以由索引模板本身组成,因此有两个模拟API来确定生成的索引设置
  • 模拟te-000001 :
POST /_index_template/_simulate_index/te-000001
  • 获取特定模板的设置:
POST /_index_template/_simulate/template_1
  • 从现有模板应用Simulate的设置:
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" }
            } 
          } 
        } 
      }
    }
 }
  • 关键设置包括:
    • template for index-pattern
      • 只有匹配 logstash-* 的索引才会应用这个模板
    • refresh_interval for indexing
      • Elasticsearch 是一个近实时搜索引擎
    • multi-field with not_analyzed
      • Elasticsearch 会自动使用自己的默认分词器(空格,点,斜线等分割)来分析字段
    • geo_point
      • Elasticsearch 支持 geo_point 类型, geo distance 聚合等等
  • 其他模板配置建议
    • doc_values
      • 在请求范围加大的时候,很容易触发 OOM 报错:
        • doc_values 只能给不分词(对于字符串字段就是设置了"index":"not_analyzed",数值和时间字段默认就没有分词) 的字段配置生效
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
      • order 就是 elasticsearch 在创建一个索引的时候,发现这个索引同时匹配上了多个 template ,那么就会先应用 order 数值小的 template 设置,然后再应用一遍 order 数值高的作为覆盖,最终达到一个 merge 的效果
      • 比如,上面这个模板只想修改一下 refresh_interval ,那么只需要新写一个:
{
  "order" : 1,
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : 
"20s"
  }
}

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

相关文章

  • 18.Elasticsearch索引模板-2

    18.1 Simulate多组件模板 由于模板不仅可以由多个组件模板组成,还可以由索引模板本身组成,因此有两个模拟...

  • elastichsearch index template模板字

    索引模板(index template)是指,通过创建一些模板,使后续在创建索引时,若索引名符合模板中index_...

  • 17.Elasticsearch索引模板-1

    17.1 索引模板介绍 索引模板是告诉Elasticsearch如何在创建索引时配置索引的一种方法对于数据流,索引...

  • ES的基础使用

    索引模板 如果更改了模板不能对已存在索引生效 创建索引 下面创建一个名字为 laravel_es 的模板,mapp...

  • elasticsearch之索引模板

    索引模板简介 索引模板是创建索引的一种方式。将数据写入指定索引时,如果该索引不存在,则根据索引名称能匹配相应索引模...

  • 基于 IK 分词器的 ES 通用索引模板

    一、索引模板 1、模板简述 ES 允许用户定义一系列模板,当索引被创建的时候,模板的设置会自动被应用到新创建的索引...

  • 根据数据和模板动态生成页面

    1、根据规则去解析链接,并且获取ID或者索引值 2、根据索引获取数据 3、根据模板渲染页面 4、底层需要实现渲染函...

  • ElasticSearch索引模板

    索引模板 简介 在ElasticSearch中创建索引时,可以为创建的索引指定索引的属性设定,映射关系,别名等操作...

  • ES支持中文&&全拼&&拼音首字母搜索

    环境 Ubuntu18.04 ES 6.6.1 搜索模板 新建模板,便于后续创建索引,直接使用模板,省事方便 新建...

  • Elasticsearch 通用索引模板

    1、模板简述 ES 允许用户定义一系列模板,当索引被创建的时候,模板的设置会自动被应用到新创建的索引中,这一系列模...

网友评论

    本文标题:18.Elasticsearch索引模板-2

    本文链接:https://www.haomeiwen.com/subject/gxfpjrtx.html