Last active
April 7, 2016 08:50
-
-
Save jrgns/5ad91e069923eb384eab3e6af0938290 to your computer and use it in GitHub Desktop.
Convert feedback from Elasticsearch's /_cat/indices endpoint to a Ruby hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def indices | |
client.cat.indices.split("\n").map do |line| | |
line = Hash[*[ | |
:health, | |
:state, | |
:index, | |
:primaries , | |
:replicas, | |
:count, | |
:deleted, | |
:total_size, | |
:size | |
].zip(line.split(' ')).flatten] | |
[:primaries, :replicas, :count, :deleted].each {|key| line[key] = line[key].to_i} | |
line | |
end | |
end | |
def client | |
@client ||= ::Elasticsearch::Client.new(host: 'http://localhost:9200') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment