Elasticsearch 索引模板、生命周期策略、节点角色,8年大数据开发开发教你如何写简历
    		       		warning:
    		            这篇文章距离上次修改已过440天,其中的内容可能已经有所变动。
    		        
        		                
                在Elasticsearch中,索引模板(Index templates)用于预定义索引的设置和映射,以便在创建新索引时自动应用。生命周期管理(ILM)用于管理索引的生命周期,包括索引的归档、删除等。节点角色定义了集群中不同类型的节点,如主节点、数据节点等。
以下是如何定义索引模板、使用生命周期管理策略以及配置节点角色的示例代码:
- 定义索引模板:
PUT _template/my_template
{
  "index_patterns": ["my_logs-*"],
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date"
      }
    }
  }
}- 定义ILM策略:
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_age": "7d",
            "max_docs": 10000
          }
        }
      },
      "warm": {
        "min_age": "30d",
        "actions": {
          "allocate": {
            "include": {
              "box_type": "warm"
            }
          },
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "cold": {
        "min_age": "60d",
        "actions": {
          "allocate": {
            "include": {
              "box_type": "cold"
            },
            "require": {
              "box_type": "cold"
            }
          },
          "readonly": {}
        }
      },
      "delete": {
        "min_age": "90d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}- 配置节点角色: - 在 - elasticsearch.yml配置文件中设置节点角色:
node.roles: ["data", "ingest"]在这个例子中,我们创建了一个索引模板,用于匹配所有以my_logs-开头的索引,并为它们定义了一些默认的设置和映射。然后,我们定义了一个ILM策略,用于控制索引的生命周期,包括滚动、分配到不同的节点类型,以及在合适的时间删除数据。最后,我们在elasticsearch.yml中配置了节点角色,指定了这个节点是数据节点和处理插件任务的节点。
评论已关闭