ES命令

记录实际工作中使用的命令以及脚本

  • ES追加启动参数

    1
    2
    设定heapsize
    ES_JAVA_OPTS="-Xms60g -Xmx60g" ./bin/elasticsearch
  • ES处理大量分片未分配脚本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #!/bin/bash

    for index in $(curl -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | awk '{print $1}' | sort | uniq); do
    for shard in $(curl -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | grep $index | awk '{print $2}' | sort | uniq); do
    echo $index $shard

    curl -XPOST 'localhost:9200/_cluster/reroute' -d "{
    'commands' : [ {
    'allocate' : {
    'index' : $index,
    'shard' : $shard,
    'node' : 'Master',
    'allow_primary' : true
    }
    }
    ]
    }"

    sleep 5
    done
    done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!bin/sh

NODE="$(hostname)"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))

curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands": [
{
"allocate": {
"index": "'$INDEX'",
"shard": '$SHARD',
"node": "'$NODE'",
"allow_primary": true
}
}
]
}'
echo $INDEX
echo $SHARD
done