[Elasticsearch] List all indexes and optimize it.

When we deleted the indexes, the data were just marked by deleted.
We can list all indexes to show status.

sudo curl 'localhost:9200/_cat/indices?v'

It will show the health, index name, pri, rep, docs.count, docs.deleted, store.size, pri.store.size.

health index               pri rep docs.count docs.deleted store.size pri.store.size
yellow kibana-int            5   1          5            0     66.7kb         66.7kb
yellow logstash-2015.02.13   5   1     402030      3366353      1.2gb          1.2gb
yellow logstash-2015.02.18   5   1      86843      3393979      1.1gb          1.1gb
yellow logstash-2015.02.15   5   1     218402      3063776      1.2gb          1.2gb
yellow logstash-2015.02.03   5   1     178621      2072000    756.3mb        756.3mb
yellow logstash-2015.02.06   5   1     466185      2479658    963.4mb        963.4mb
yellow logstash-2015.02.24   5   1     364473            0    166.5mb        166.5mb
yellow logstash-2015.02.02   5   1     313488      1838855    710.1mb        710.1mb
yellow logstash-2015.02.07   5   1     371602      3397300      1.2gb          1.2gb
yellow logstash-2015.02.21   5   1    3583288            0      1.2gb          1.2gb
yellow logstash-2015.02.22   5   1    3554707            0      1.1gb          1.1gb
yellow logstash-2015.02.23   5   1    3680625            0      1.2gb          1.2gb

If we want to clear the deleted indexes, we can optimize it.

sudo curl -XPOST 'http://localhost:9200/_optimize'

And it will reply this message.

{"_shards":{"total":310,"successful":155,"failed":0}}

Then when we list all indexes again, we will see the deleted indexes are gone.

cowman@roamingcacti:~$ sudo curl 'localhost:9200/_cat/indices?v'
health index               pri rep docs.count docs.deleted store.size pri.store.size
yellow kibana-int            5   1          5            0     66.5kb         66.5kb
yellow logstash-2015.02.13   5   1     402030      1512300    611.7mb        611.7mb
yellow logstash-2015.02.18   5   1      86843      1374178    491.9mb        491.9mb
yellow logstash-2015.02.15   5   1     218402      1404862    536.7mb        536.7mb
yellow logstash-2015.02.03   5   1     178621      2072000    756.2mb        756.2mb
yellow logstash-2015.02.06   5   1     466185      2479658    963.4mb        963.4mb
yellow logstash-2015.02.24   5   1     378777            0    156.9mb        156.9mb
yellow logstash-2015.02.02   5   1     313488      1838855    710.1mb        710.1mb
yellow logstash-2015.02.07   5   1     371602      1394610    566.5mb        566.5mb
yellow logstash-2015.02.21   5   1    3583288            0      1.2gb          1.2gb
yellow logstash-2015.02.22   5   1    3554707            0      1.1gb          1.1gb
yellow logstash-2015.02.23   5   1    3680625            0      1.2gb          1.2gb
This entry was posted in Elasticsearch. Bookmark the permalink.