Skip to content

Instantly share code, notes, and snippets.

@jrgns
Last active April 7, 2016 08:50
Show Gist options
  • Save jrgns/5ad91e069923eb384eab3e6af0938290 to your computer and use it in GitHub Desktop.
Save jrgns/5ad91e069923eb384eab3e6af0938290 to your computer and use it in GitHub Desktop.
Convert feedback from Elasticsearch's /_cat/indices endpoint to a Ruby hash
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