Journal

Writing down the things I learned. To share them with others and my future self.

04 May 2020

Migrate Elasticsearch 5.x to 6.x

We want to migrate an pre 6.0.0 cluster to 6.x.x. Therefore we have to make sure every index contains only one mapping. The following snippets shows how to inspect the indices with default unix tools.

Required tools:

1
2
3
4
5
6
cat
jq
curl
mkdir
wc
echo

To decrease the load on the cluster we download the mappings of every index to /tmp/indices.

1
2
3
esHost="http://localhost:9200"
mkdir /tmp/indices
for i in $(curl "${esHost}/_cat/indices?h=index"); do curl "${esHost}/${i}/_mapping" > /tmp/indices/${i}.json; done

Show the number of mappings for all indices:

1
for i in $(ls -1 /tmp/indices); do echo -n $i " ";jq '.[].mappings | to_entries[].key' /tmp/indices/${i} | wc -l; done

Show the names of mappings in an index:

1
2
index="index-name"
cat /tmp/indices/${index}.json | jq ".[\"${index}\"].mappings | to_entries[].key"