 #   Get ElasticSearch Cluster Information
 #
 # Commands:
-#   hubot: elasticsearch cluster [server] - Gets the cluster information for the given server
+#   hubot: elasticsearch|es cluster [server] - Gets the cluster information for the given server
 #   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|es show aliases - shows the aliases for the list of ElasticSearch instances

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

  robot.respond /elasticsearch cluster (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return

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

  robot.respond /(elasticsearch|es) show aliases/i, (msg) ->
    if msg.message.user.id is robot.name
      return

    showAliases msg, (text) ->
      msg.send(text)

  robot.respond /(elasticsearch|es) add alias (.*) (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return

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

  robot.respond /(elasticsearch|es) clear alias (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return

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

  showAliases = (msg) ->
    if _esAliases?
      msg.send("I cannot find any ElasticSearch Cluster aliases")
    else
      for alias of _esAliases
        msg.send("I found '#{alias}' as an alias for #{_esAliases[alias]}")

  clearAlias = (msg, alias) ->
    delete _esAliases[alias]
    robot.brain.data._esAliases = _esAliases
    msg.send("The alias #{alias} has been removed")

  setAlias = (msg, alias, url) ->
    _esAliases[alias] = url
    robot.brain.data.elasticsearch_aliases = _esAliases
    msg.send("The alias #{alias} for #{url} has been added to the brain")

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

  robot.respond /elasticsearch node (.*)/i, (msg) ->
    if msg.message.user.id is robot.name
      return
