解决方法:(1)如果是红色的,可以直接分片shard给你认为有最新(或最多)数据的节点。见下:

摘自:https://discuss.elastic.co/t/how-to-resolve-the-unassigned-shards/87635

Use the reroute command to assign the unassigned shard to a node.

If your cluster is red then you probably have primary shards unassigned. The command below will allow you to reassign a shard that has gone "stale"(腐烂不新鲜的). This means that ES is not sure which copy of the shard has the most recent data and it will not assign one as primary because if another shard with newer data connects to the cluster later it will be overwritten. If your confident that the shard has all of the data you need then you can assign it to a node with the command below. Just be wary of data loss。

curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -H 'Content-Type: application/json' -d'
{
"commands" : [
{
"allocate_stale_primary" : {
"index" : "test", "shard" : 1,
"node" : "node3",
"accept_data_loss" : true
}
}
]
}
'
https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html

(2)如果集群是黄色的,可以等其恢复

The status may be one of three values:

green
All primary and replica shards are allocated. Your cluster is 100% operational.
yellow
All primary shards are allocated, but at least one replica is missing. No data is missing, so search results will still be complete. However, your high availability is compromised to some degree. If moreshards disappear, you might lose data. Think of yellow as a warning that should prompt investigation.
red
At least one primary shard (and all of its replicas) is missing. This means that you are missing data: searches will return partial results, and indexing into that shard will return an exception.

The green/yellow/red status is a great way to glance at your cluster and understand what’s going on. The rest of the metrics give you a general summary of your cluster:

  • number_of_nodes and number_of_data_nodes are fairly self-descriptive.
  • active_primary_shards indicates the number of primary shards in your cluster. This is an aggregate total across all indices.
  • active_shards is an aggregate total of all shards across all indices, which includes replica shards.
  • relocating_shards shows the number of shards that are currently moving from one node to another node(现网中遇到,因为kill -9重启es的方法不对,导致node下线,集群重新分配shard). This number is often zero, but can increase when Elasticsearch decides a cluster is not properly balanced, a new node is added, or a node is taken down, for example(原因).
  • initializing_shards is a count of shards that are being freshly created. For example, when you first create an index, the shards will all briefly reside in initializing state. This is typically a transient event, and shards shouldn’t linger in initializing too long. You may also see initializing shards when a node is first restarted: as shards are loaded from disk, they start as initializing.(现网遇到过)
  • unassigned_shards are shards that exist in the cluster state, but cannot be found in the cluster itself. A common source of unassigned shards are unassigned replicas. For example, an index with five shards and one replica will have five unassigned replicas in a single-node cluster. Unassigned shards will also be present if your cluster is red (since primaries are missing).

Drilling Deeper: Finding Problematic Indices

Imagine something goes wrong one day, and you notice that your cluster health looks like this:

{
"cluster_name": "elasticsearch_zach",
"status": "red",
"timed_out": false,
"number_of_nodes": 8,
"number_of_data_nodes": 8,
"active_primary_shards": 90,
"active_shards": 180,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 20
}

OK, so what can we deduce from this health status? Well, our cluster is red, which means we are missing data (primary + replicas). We know our cluster has 10 nodes, but see only 8 data nodes listed in the health. Two of our nodes have gone missing. We see that there are 20 unassigned shards.

That’s about all the information we can glean. The nature of those missing shards are still a mystery. Are we missing 20 indices with 1 primary shard each? Or 1 index with 20 primary shards? Or 10 indices with 1 primary + 1 replica? Which index?

To answer these questions, we need to ask cluster-health for a little more information by using the level parameter:

GET _cluster/health?level=indices

This parameter will make the cluster-health API add a list of indices in our cluster and details about each of those indices (status, number of shards, unassigned shards, and so forth):

{
"cluster_name": "elasticsearch_zach",
"status": "red",
"timed_out": false,
"number_of_nodes": 8,
"number_of_data_nodes": 8,
"active_primary_shards": 90,
"active_shards": 180,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 20
"indices": {
"v1": {
"status": "green",
"number_of_shards": 10,
"number_of_replicas": 1,
"active_primary_shards": 10,
"active_shards": 20,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0
},
"v2": {
"status": "red",

         "number_of_shards": 10,
"number_of_replicas": 1,
"active_primary_shards": 0,
"active_shards": 0,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 20

      },
"v3": {
"status": "green",
"number_of_shards": 10,
"number_of_replicas": 1,
"active_primary_shards": 10,
"active_shards": 20,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0
},
....
}
}

We can now see that the v2 index is the index that has made the cluster red.

And it becomes clear that all 20 missing shards are from this index.

Once we ask for the indices output, it becomes immediately clear which index is having problems: the v2 index. We also see that the index has 10 primary shards and one replica, and that all 20 shards are missing. Presumably these 20 shards were on the two nodes that are missing from our cluster.

摘自:https://www.elastic.co/guide/en/elasticsearch/guide/current/_cluster_health.html

ES 遇到 unassigned shard如何处理?的更多相关文章

  1. 处理 unassigned shard

    #查看所有分片 GET _cat/shards curl  10.1.2.2:9200/_cat/indices/iis_log* #查看索引的分片状态 #查看第一个unassigned shard的 ...

  2. 磁盘空间引起ES集群shard unassigned的处理过程

    1.问题描述 早上醒来发现手机有很多ES状态为red的告警,集群就前几天加了几个每天有十多亿记录的业务,当时估算过磁盘容量,应该是没有问题的,但是现在集群状态突然变成red了,这就有点懵逼了. 2.查 ...

  3. Reroute Unassigned Shards——遇到主shard 出现的解决方法就是重新路由

    Red Cluster! 摘自:http://blog.kiyanpro.com/2016/03/06/elasticsearch/reroute-unassigned-shards/ There a ...

  4. 4.ES核心慨念

    一. 和lucene的关系 lucene是最先进,功能最强大的搜索库.但是使用复杂(要深入理解其中原理. elasticsearch,基于lucene,隐藏复杂性,提供简单易用的restful api ...

  5. es故障节点恢复后加入集群导致删除索引重新出现

    es的每个shard下的文件都可以看做一个完整的lucene文件,shard数据目录下的segment文件包含了索引的分片数量,副本数量.es shard可以恢复,就是因为每个shard都包含了一份数 ...

  6. es修改指定的field(partial update)

    PUT /index/type/id 创建文档&替换文档,就是一样的语法一般对应到应用程序中,每次的执行流程基本是这样的:1.应用程序发起一个get请求,获取到document,展示到前台界面 ...

  7. 节点回来shard仍然delayed原因

    1:es2 fetch shard data时,存在节点刚加入集群,还没有收到cluster metadata的情况.此时,节点因为没有该索引,返回的sharddata为empty,主节点缓存了该sh ...

  8. elasticsearch 产生未分配分片的原因(es官网)

    Reasons for unassigned shard: These are the possible reasons for a shard to be in a unassigned state ...

  9. 【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!

    前言 说到 Elasticsearch ,其中最明显的一个特点就是 near real-time 准实时 -- 当文档存储在Elasticsearch中时,将在1秒内以几乎实时的方式对其进行索引和完全 ...

随机推荐

  1. 2016.02.23,英语,《Vocabulary Builder》Unit 01

    Bell:来源于拉丁语,含义为war.fight,其中Bellona [bә'lәunә]是罗马女战神的名字,她的丈夫是战神Mars.antebellum: [ˌænti'beləm] adj. 战前 ...

  2. C4

    #include <stdio.h> int main(int argc, const char * argv[]) { // int 占用4个字节 double 占用8个字节 // 只是 ...

  3. caioj1497&&bzoj3125: CITY

    震惊!bzoj居然又被苏大佬D飞了... 这题煞笔模板题好吧. 然而bzojAC caiojWA%40??? 好强啊 今天早上发现是m打成n了囧 #include<cstdio> #inc ...

  4. hmm CDN检测

    # -*- coding:utf-8 -*- import sys import re from hmmlearn import hmm import numpy as np from sklearn ...

  5. 【BZOJ 2453】 维护队列

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2453 [算法] 带修改的莫队算法 当块的大小为N^(2/3)时,时间复杂度为 : O ...

  6. POJ 2239 匈牙利算法

    思路:最大匹配 也是很裸的一道题-. // by SiriusRen #include <cstdio> #include <cstring> #include <alg ...

  7. ElementUI 表格表头筛选框的高度设置,超出一定高度,显示滚动条

    最近项目发现一个问题table表头筛选的时候,由于筛选内容过多导致弹出框超出屏幕,并且无法滚动,应急的办法是缩小浏览器显示比例让更多内容显示

  8. Java基础——增强for循环

    java1.5版本引入了一个增强for循环,基本原理和for循环类似. 语法声明:for(表达式:条件表达式) 举例:for (String str : set) 解释:set代表set集合,str代 ...

  9. P1726 上白泽慧音(0分)

    题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...

  10. Android 自定义简单控件--星级评价

    效果图 实现 package com.easypass.carstong.view; import android.content.Context; import android.content.re ...