Elasticsearch——Rollover的正确使用姿势
elasticsearch 使用 正确 姿势
2023-06-13 09:17:22 时间
一、常见报错信息
# kibana-Index Management页面报错
Index lifecycle error
illegal_argument_exception: index.lifecycle.rollover_alias [niosec-endpointsecurity-huorong-all] does not point to index [niosec-endpointsecurity-huorong-prod]
Index lifecycle error
illegal_argument_exception: index.lifecycle.rollover_alias [niosec-endpointsecurity-huorong-prod] does not point to index [niosec-endpointsecurity-huorong-prod]
二、操作步骤
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html
- The index name must match the pattern ^.*-\d+$, for example (my-index-000001). The index.lifecycle.rollover_alias must be configured as the alias to roll over. The index must be the write index for the alias.
1. 创建索引(索引名称必须得满足以上3个条件)
# 创建索引并指定lifecycle与aliases属性
PUT my-index-000001
{
"settings": {
"index.lifecycle.name": "my_policy",
"index.lifecycle.rollover_alias": "my_data"
},
"aliases": {
"my_data": {
"is_write_index": true
}
}
}
# 返回
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "my-index-000001"
}
___
- 如果是已有index名称(xxxxxx)不满足条件,则需要reindex其到xxxxxx-000001
POST _reindex
{
"source": {
"index": "xxxxxx"
},
"dest": {
"index": "xxxxxx-000001"
}
}
# 对其设置lifecycle属性
PUT xxxxxx-000001/_settings
{
"index.lifecycle.name": "my_policy",
"index.lifecycle.rollover_alias": "my_data"
}
# 对其添加aliases
PUT xxxxxx-000001/_aliases/my_data
{
"is_write_index": true
}
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html
2. 创建生命周期策略
PUT _ilm/policy/my_policy/
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover" : {
"max_primary_shard_size": "50GB"
}
}
}
}
}
}
具体滚动策略根据业务需要自行选择 https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html
3. 验证rollover api
# 写入一条数据
PUT my-index-000001/_doc/1
{
"name": "weldon",
"address": "陕西省西安市"
}
# 返回
{
"_index" : "my-index-000001",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
# 验证当前索引设置、alias指向
GET _cat/indices/my-index*?v
GET my-index-000001/_settings
GET my-index-000001/_alias
GET _alias/my_data
# 返回见下图
# 执行rollover apiapi,我这里max_docs指定的是1哦(因为我只写入了1条数据),如果指定为2则不满足rollover条件,conditions返回就为false
POST my_data/_rollover
{
"conditions": {
"max_docs": 1
}
}
# 返回
{
"acknowledged" : true,
"shards_acknowledged" : true,
"old_index" : "my-index-000001",
"new_index" : "my-index-000002",
"rolled_over" : true,
"dry_run" : false,
"conditions" : {
"[max_docs: 1]" : true
}
}
相关文章
- Fabric.js 使用纯色遮挡画布(前景色)
- EFK(Elasticsearch+Filebeat+Kibana)日志收集系统
- 安装Elasticsearch
- 3.ElasticSearch分布式数据分析引擎基础概念与使用
- 03-Elasticsearch-基本语法
- 【优秀最佳实践展播】第11期:Elasticsearch Service
- Elasticsearch多集群监控管理工具
- 【日志审计】极易上手搭建自己日志采集服务器分析日志(winlogbeat+Elasticsearch+Kibana)
- Elasticsearch 警惕使用 wildcard 检索!然后呢?
- 通过Logstash复制MySQL数据到ElasticSearch
- 使用spring-boot-starter-data-elasticsearch 设置了long,为什么却变成了keyword类型
- 【ES三周年】基础的ElasticSearch的环境搭建和使用
- 【ES三周年】ElasticSearch中文分词
- 【Elasticsearch】整合Spring Data Elasticsearch
- Linux安装ElasticSearch
- ElasticSearch客户端调用
- 【ES三周年】Win10安装ElasticSearch笔记
- ChatGPT 和 Elasticsearch的结合:在私域数据上使用ChatGPT
- ElasticSearch(五) Elasticsearch-jdbc实现MySQL同步到ElasticSearch详解程序员
- 如何在Django中使用ElasticSearch