• ES 生命周期管理


    一 .概念

    ILM定义了四个生命周期阶段:
    Hot:正在积极地更新和查询索引
    Warm:不再更新索引,但仍在查询。
    cold:不再更新索引,很少查询。信息仍然需要可搜索,但是如果这些查询速度较慢也可以。
    Delete:不再需要该索引,可以安全地将其删除

    仅仅在 Hot阶段 可以设置 rollover滚动

    在实验中可以修改设置,来缩短ILM检测时间间隔。ILM定期运行(indices.lifecycle.poll_interval),默认是10分钟,检查索引是否符合策略标准,并执行所需的任何步骤

    1. PUT /_cluster/settings
    2. { "transient": { "indices.lifecycle.poll_interval": "1m" } }

    参数的设置:满足任意一个创建新的索引

    HOT

    WARM

    Delete

    二. 实战

    1 .创建生命周期策略模板:PUT 请求

    http://localhost:9099/_ilm/policy/my_index_rollover_policy

    "max_docs": 5000000 设置超过500万是创建新的索引,实际测试可以设置小一点

    1. {
    2. "policy": {
    3. "phases": {
    4. "hot": {
    5. "actions": {
    6. "rollover": {
    7. "max_docs": 5000000
    8. },
    9. "set_priority": {
    10. "priority": 100
    11. }
    12. }
    13. },
    14. "warm": {
    15. "min_age": "30d",
    16. "actions": {
    17. "forcemerge": {
    18. "max_num_segments": 1
    19. },
    20. "shrink": {
    21. "number_of_shards": 1
    22. },
    23. "allocate": {
    24. "number_of_replicas": 1
    25. },
    26. "set_priority": {
    27. "priority": 50
    28. }
    29. }
    30. },
    31. "cold": {
    32. "min_age": "90d",
    33. "actions": {
    34. "freeze": {},
    35. "allocate": {
    36. "require": {
    37. "type": "cold"
    38. }
    39. },
    40. "set_priority": {
    41. "priority": 10
    42. }
    43. }
    44. },
    45. "delete": {
    46. "min_age": "3650d",
    47. "actions": {
    48. "delete": {}
    49. }
    50. }
    51. }
    52. }
    53. }

    2. 创建索引模板(日志统计索引) PUT 请求

    http://localhost:9099/_template/my_statistic_log

    1. {
    2. "index_patterns": [
    3. "my_statistic_log-*"
    4. ],
    5. "settings": {
    6. "index.number_of_shards": 5,
    7. "index.number_of_replicas": 1,
    8. "refresh_interval": "60s",
    9. "index.lifecycle.name": "my_index_rollover_policy",
    10. "index.lifecycle.rollover_alias": "statistic_log_write"
    11. },
    12. "aliases": {
    13. "statistic_log_read": {}
    14. },
    15. "mappings": {
    16. "log": {
    17. "dynamic": "strict",
    18. "_field_names": {
    19. "enabled": false
    20. },
    21. "dynamic_templates": [
    22. {
    23. "date": {
    24. "match": "*Date",
    25. "mapping": {
    26. "type": "date"
    27. }
    28. }
    29. },
    30. {
    31. "strings": {
    32. "match_mapping_type": "string",
    33. "mapping": {
    34. "type": "keyword"
    35. }
    36. }
    37. },
    38. {
    39. "long_or_text": {
    40. "match": "*Time",
    41. "mapping": {
    42. "type": "date"
    43. }
    44. }
    45. },
    46. {
    47. "dataFormat": {
    48. "match": "*Date",
    49. "mapping": {
    50. "type": "date"
    51. }
    52. }
    53. },
    54. {
    55. "timeFormat": {
    56. "match": "*Time",
    57. "mapping": {
    58. "type": "date"
    59. }
    60. }
    61. },
    62. {
    63. "noAnalyzed": {
    64. "match_mapping_type": "string",
    65. "mapping": {
    66. "type": "keyword"
    67. }
    68. }
    69. }
    70. ],
    71. "properties": {
    72. "area": {
    73. "type": "keyword"
    74. },
    75. "desc": {
    76. "type": "keyword"
    77. },
    78. "hour": {
    79. "type": "integer"
    80. },
    81. "day": {
    82. "type": "integer"
    83. },
    84. "startTime": {
    85. "type": "date",
    86. "format": "yyyy-MM-dd HH:mm:ss"
    87. },
    88. "totalCount": {
    89. "type": "long"
    90. }
    91. }
    92. }
    93. }
    94. }

    3.    根据索引模板创建起始索引(日志统计索引)
    put 请求: http://localhost:9099/my_statistic_log-000001

    1. {
    2. "aliases": {
    3. "statistic_log_write": {
    4. "is_write_index": true
    5. }
    6. }
    7. }

    4.    查看索引生效:GET请求 
    http://localhost:9099/my_statistic_log-000001/_ilm/explain

    https://www.elastic.co/guide/en/elasticsearch/reference/6.8/_setting_up_a_new_policy.html

  • 相关阅读:
    深入剖析:垃圾回收你真的了解吗?
    Neo4j 新手教程 环境安装 基础增删改查 python链接 常用操作 纯新手向
    Selenium打开页面,出现弹窗需要登录账号密码,怎么解决?
    编程技巧│Gitee 的 WebHooks 实现代码自动化部署
    Servlet导坐标,创建入门(有图有代码有过程)
    vue学习001
    12个微服务架构模式最佳实践
    ABP - 依赖注入(1)
    第43期:多表关联场景下如何用好分区表
    1×1 问题详解
  • 原文地址:https://blog.csdn.net/LZHH_2008/article/details/139358245