   robot.brain.on 'loaded', ->
     if robot.brain.data.elasticsearch_aliases?
       _esAliases = robot.brain.data.elasticsearch_aliases
-
-  # search = (msg, server, query) ->
-  #   msg.http("http://#{server}/_search?#{query}")
-  #     .get() (err, res, body) ->
-  #       json = JSON.parse(body)
-  #       firsthit = JSON.stringify(json.hits.hits[0])
-  #       msg.send("There are #{json.hits.total} results for the search http://#{server}/_search?#{query} \nThe first result is \n#{firsthit}")
 
   cluster_health = (msg, alias) ->
     cluster_url = _esAliases[alias]

#
# Commands:
#   hubot: elasticsearch cluster [server] - Gets the cluster information for the given server or alias
#   hubot: elasticsearch node [server] - Gets the node information for the given server
#   hubot: elasticsearch query [server] [query] - Runs a specific query against an ElasticSearch cluster
#   hubot: elasticsearch show aliases - shows the aliases for the list of ElasticSearch instances
#   hubot: elasticsearch add alias [alias name] [url] - sets the alias for a given url
#   hubot: elasticsearch clear alias [alias name] - please note that this needs to include any port numbers as appropriate

      msg.send("Getting the cat stats for the cluster: #{cluster_url}")
      msg.http("#{cluster_url}/_cat/nodes?h=host,heapPercent,load,segmentsMemory,fielddataMemory,filterCacheMemory,idCacheMemory,percolateMemory,u,heapMax,nodeRole,master")
        .get() (err, res, body) ->
          lines  = body.split("\n")
          header = lines.shift()
          list   = [header].concat(lines.sort().reverse()).join("\n")
          msg.send("/code #{list}")

  cat_indexes = (msg, alias) ->
    cluster_url = _esAliases[alias]

    if cluster_url == "" || cluster_url == undefined
      msg.send("No ES Cluster found for #{alias}")
    else
      msg.send("Getting the cat indices for the cluster: #{cluster_url}")
      msg.http("#{cluster_url}/_cat/indices/logstash-*?h=idx,sm,fm,fcm,im,pm,ss,sc,dc&v")
        .get() (err, res, body) ->
          lines  = body.split("\n")
          header = lines.shift()
          list   = [header].concat(lines.sort().reverse()).join("\n")
          msg.send("/code #{list}")

  robot.hear /elasticsearch cat nodes (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return

    cat_nodes msg, msg.match[1], (text) ->
      msg.send text

  robot.hear /elasticsearch cat indexes (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return

    cat_indexes msg, msg.match[1], (text) ->
      msg.send text

  robot.hear /elasticsearch cluster (.*)/i, (msg) ->
