Elasticsearch: illegal_argument_exception: index [xxx] is not the write index for alias [xxx]

问题由来: 因为公司要进行发版一个新版本,需要要保留指定URL的数据不被定时删除,此时Kinbana就无法满足这个条件啦, 于是我就把index和lifecycle的关系全部解除啦, 走Java 代码,但是发现效果并不是很好,于是回滚的时候,原封不动得执行了当初第一次kinbana的配置,此时线上已经从0009 ~ 00045 这些都是滚动索引

## 删除所有的别名
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "process-log-*",
        "alias": "process-log"
      }
    }
  ]
}

## 解除索引和策略的绑定
POST process-log-*/_ilm/remove

## 删除模板
DELETE  _template/process-log-template

## 增加模板
PUT _template/process-log-template
{
  "index_patterns": ["process-log-*"],
  "settings": {
    "number_of_shards": 2,
    "index.lifecycle.name": "process-log-lifecycle", 
    "index.lifecycle.rollover_alias": "process-logs",
    "index" : {
            "sort.field" : "requestTime", 
            "sort.order" : "desc" 
        }
  },
  "mappings": {
    
    "properties":{
      "consumeTime": {
        "type": "long"
      },
      "insertTime": {
        "type": "long"
      },
      "ip": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "method": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "params": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "requestTime": {
        "type": "long"
      },
      "requestUri": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "responseTime": {
        "type": "long"
      },
      "result": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "serverName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "status": {
        "type": "long"
      },
      "userAgent": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    
    }
  }
}
## 增加别名
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "process-log-*",
        "alias": "process-logs"
      }
    },
    {
      "add": {
        "index": "process-log-000045",
        "alias": "process-logs",
        "is_write_index": true
      }
    }
  ]
}

## 将索引添加到模板中
PUT _template/process-log-template
{
  "index_patterns": ["process-log-*"],  
  "settings": {
    "index.lifecycle.name": "process-log-lifecycle"
  }
}


但是发现大概过了10分钟左右 索引都会报这个错.问题的原因在于他不知道哪个索引是否需要滚动.
在这里插入图片描述
我经过简单如下的配置,解决了这个问题

# 解除和索引和策略的绑定
POST process-log-*/_ilm/remove
##删除策略
DELETE _ilm/policy/process-log-lifecycle
##增加策略
PUT _ilm/policy/process-log-lifecycle
{
    "policy": {
        "phases": {
            "hot": {
                "min_age": "0ms",
                "actions": {
                    "rollover": {
                        "max_age": "30d",
                        "max_size": "20gb"
                    },
                    "set_priority": {
                        "priority": 100
                    }
                }
            },
            "delete": {
                "min_age": "90d",
                "actions": {
                    "delete": {}
                }
            }
        }
    }
}
## 删除模板
DELETE  _template/process-log-template
## 增加模板
PUT _template/process-log-template
{
  "index_patterns": ["process-log-*"],
  "settings": {
    "number_of_shards": 2,
    "index.lifecycle.name": "process-log-lifecycle", 
    "index.lifecycle.rollover_alias": "process-log",
    "index" : {
            "sort.field" : "requestTime", 
            "sort.order" : "desc" 
        }
  },
  "mappings": {
    "properties":{
      "consumeTime": {
        "type": "long"
      },
      "insertTime": {
        "type": "long"
      },
      "ip": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "method": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "params": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "requestTime": {
        "type": "long"
      },
      "requestUri": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "responseTime": {
        "type": "long"
      },
      "result": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "serverName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "status": {
        "type": "long"
      },
      "userAgent": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}
## 去除别名
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "process-log-*",
        "alias": "process-logs"
      }
    }
  ]
}
## 增加别名
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "process-log-*",
        "alias": "process-log",
        "is_write_index": false
      }
    },
    {
      "add": {
        "index": "process-log-000045",
        "alias": "process-log",
        "is_write_index": true
      }
    }
  ]
}
#将索引放入模板和策略中,并且制定全部索引不需要滚动
PUT process-log-*/_settings 
{
  "index": {
    "lifecycle": {
      "name": "process-log-lifecycle",
      "rollover_alias": "process-log",
      "indexing_complete": "true"
    }
  }
}
#将索引放入模板和策略中,并且制定最新的索引需要滚动,指定他需要滚动
PUT process-log-000045/_settings 
{
  "index": {
    "lifecycle": {
      "name": "process-log-lifecycle",
      "rollover_alias": "process-log",
      "indexing_complete": "false"
    }
  }
}

到此,困扰了我3天的问题,终于解决

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值