Elasticsearch command line tool (for Elasticsearch 1.x)
Go Shell
Latest commit 71e450c Apr 8, 2016 @olivere Update README.md
Failed to load latest commit information.
autocompletion Fix missing completions Jun 13, 2015
.gitignore List, dump, create, and delete templates Jul 5, 2012
MIT-LICENSE first commit Jul 5, 2012
README.md Update README.md Apr 8, 2016
aliases.go Add aliases-related commands Sep 27, 2012
api.go Add cluster-nodes, cluster-state, (basic) search, and bulk import APIs Jul 5, 2012
buildcmd Add aliases-related commands Sep 27, 2012
bulk.go Docs and -v/--verbose flag for bulk command Nov 26, 2012
close_index.go Add snapshot related commands Jun 13, 2015
cluster_health.go Add cluster health API Jul 5, 2012
cluster_nodes.go Add cluster-nodes, cluster-state, (basic) search, and bulk import APIs Jul 5, 2012
cluster_state.go Add cluster-nodes, cluster-state, (basic) search, and bulk import APIs Jul 5, 2012
count.go add simple count command Sep 2, 2014
create_index.go Put mappings, API help etc. Jul 5, 2012
create_repo.go Add snapshot related commands Jun 13, 2015
create_snapshot.go Add snapshot related commands Jun 13, 2015
create_template.go Extract getJsonFromStdin() Jun 13, 2015
delete_index.go Put mappings, API help etc. Jul 5, 2012
delete_repo.go Add snapshot related commands Jun 13, 2015
delete_snapshot.go Add snapshot related commands Jun 13, 2015
delete_template.go Put mappings, API help etc. Jul 5, 2012
flush.go Add optimize, refresh, and flush Jul 5, 2012
flush_disable.go Update Reindexer to latest Elastic version Apr 30, 2015
flush_enable.go Update Reindexer to latest Elastic version Apr 30, 2015
help.go Put mappings, API help etc. Jul 5, 2012
index_aliases.go Add aliases-related commands Sep 27, 2012
indices.go Fixing error logging in indicies Feb 26, 2016
main.go Add snapshot related commands Jun 13, 2015
mapping.go Put mappings, API help etc. Jul 5, 2012
open_index.go Add snapshot related commands Jun 13, 2015
optimize.go Add optimize, refresh, and flush Jul 5, 2012
put_mapping.go Extract getJsonFromStdin() Jun 13, 2015
refresh.go Add optimize, refresh, and flush Jul 5, 2012
reindex.go Clarify shards/replicas in reindex command Apr 30, 2015
repo.go Add snapshot related commands Jun 13, 2015
repos.go Add snapshot related commands Jun 13, 2015
restore_snapshot.go Documentation update Jun 13, 2015
search.go Add cluster-nodes, cluster-state, (basic) search, and bulk import APIs Jul 5, 2012
settings.go New commands: settings, flush-enable, flush-disable Mar 14, 2013
snapshot.go Fix documentation Jun 13, 2015
snapshot_status.go Add snapshot related commands Jun 13, 2015
snapshots.go Add snapshot related commands Jun 13, 2015
stats.go Add stats API Jul 5, 2012
status.go Add status command. Jul 5, 2012
template.go Put mappings, API help etc. Jul 5, 2012
templates.go Put mappings, API help etc. Jul 5, 2012

README.md

Elasticsearch command line tool

es is a small command line tool to interact with the Elasticsearch search engine.

Warning This tool currently only supports Elasticsearch 1.x.

Notice that you could do all of this with curl commands, as seen on the Elasticsearch API. However, you probably save a few keystrokes with es.

Setup

You need to compile yourself currently:

  $ go get github.com/olivere/es
  $ cd $GOPATH/src/github.com/olivere/es
  $ go build
  $ ./es help

Commands

Before we start, you can always lookup the Elasticsearch API via the api command, like so:

  $ es api indices

The api command will open up a browser window with the API page that matches the specified command. You can find the complete Elasticsearch API here.

Let's get started. First we list existing indices, either all of them or via a regular expression.

  $ es indices
  master
  marvel
  dummy
  $ es indices 'm.*'
  master
  marvel

Let's create a new index. Use the -f flag to force creation, i.e. it will not print an error if the index already exists (and won't touch the existing index).

  $ es create twitter
  $ es indices
  master
  marvel
  dummy
  twitter
  $ es create twitter
  Error: IndexAlreadyExistsException[[twitter] Already exists] (400)
  $ es create -f twitter

Print some useful information with the status API.

  $ es status twitter
  { ... }

You can also get the status of all indices. Just leave out the index name.

  $ es status
  { ... }

If you need information about the number of documents in an index and such, use the stats API call. You can use it with or without an index name.

  $ es stats
  { ... }
  $ es stats twitter
  { ... }

Let's remove some indices.

  $ es delete twitter
  $ es indices
  master
  marvel
  dummy
  $ es delete twitter
  Error: IndexMissingException[[twitter] missing] (404)
  $ es delete -f twitter
  $ es indices
  master
  marvel
  dummy

Let's review mappings, and even create mappings from the command line.

  $ es mapping dummy
  {
      "dummy" : {
      }
  }
  $ es mapping nonexistent
  Error: IndexMissingException[[nonexistent] missing] (404)
  $ es create twitter
  $ es put-mapping twitter tweet < tweet-mapping.json
  $ es mapping twitter
  {
    "twitter" : {
      "tweet" : {
        "properties" : {
          "message" : {
            "type" : "string",
            "store" : "yes"
          }
        }
      }
    }
  }

Templates, oh how I love thee... here's a sample session.

  $ es templates
  dummy-template
  $ es template dummy-template
  {
  }
  $ es create-template another-template < template.json
  $ es templates
  dummy-template
  another-template
  $ es template another-template
  {
  }
  $ es delete-template another-template
  $ es delete-templete -f another-template

And, to get a list of all aliases, use:

$ es aliases
alias-1
alias-2
another-alias
$ es aliases 'al*'
alias-1
alias-2
$ es aliases -i
alias-1 -> index1
alias-2 -> index1
another-alias -> index2

Finally, there's some helper command, e.g. reindexing one index into another:

$ es reindex -v twitter twitter-snapshot

Credits

Thanks a lot for the great folks working hard on Elasticsearch and Go.

Also a big thanks to Blake Mizerany and the fast heroku client for inspiration on how to create a Go-based command line tool.