All Projects → marclop → elasticsearch-cli

marclop / elasticsearch-cli

Licence: Apache-2.0 license
Provides a REPL console-like interface to interact with Elasticsearch

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to elasticsearch-cli

Fridayuserbot
A Pluggable And Powerful Telegram Manager Bot
Stars: ✭ 183 (+1120%)
Mutual labels:  repl
Vsh
vsh - HashiCorp Vault interactive shell and cli tool
Stars: ✭ 209 (+1293.33%)
Mutual labels:  repl
Go Pry
An interactive REPL for Go that allows you to drop into your code at any point.
Stars: ✭ 2,747 (+18213.33%)
Mutual labels:  repl
Lgo
Interactive Go programming with Jupyter
Stars: ✭ 2,225 (+14733.33%)
Mutual labels:  repl
Ldb
A C++ REPL / CLI for LevelDB
Stars: ✭ 201 (+1240%)
Mutual labels:  repl
Lfortran
Official mirror of https://gitlab.com/lfortran/lfortran. Please submit pull requests (PR) there. Any PR sent here will be closed automatically.
Stars: ✭ 220 (+1366.67%)
Mutual labels:  repl
Calvin
A minimalistic build tool for clojurescript projects that does not require the jvm
Stars: ✭ 181 (+1106.67%)
Mutual labels:  repl
sliver
REPL for SilverStripe, powered by Psysh. Interactively debug and tinker with a sliver of your code.
Stars: ✭ 17 (+13.33%)
Mutual labels:  repl
Codi.vim
📔 The interactive scratchpad for hackers.
Stars: ✭ 2,464 (+16326.67%)
Mutual labels:  repl
Tslab
Interactive JavaScript and TypeScript programming with Jupyter
Stars: ✭ 240 (+1500%)
Mutual labels:  repl
Dynaml
Scala Library/REPL for Machine Learning Research
Stars: ✭ 195 (+1200%)
Mutual labels:  repl
Gluon
A static, type inferred and embeddable language written in Rust.
Stars: ✭ 2,457 (+16280%)
Mutual labels:  repl
Box
A mruby-based Builder for Docker Images
Stars: ✭ 236 (+1473.33%)
Mutual labels:  repl
Charly
🐈 The Charly Programming Language | Written by @KCreate
Stars: ✭ 185 (+1133.33%)
Mutual labels:  repl
Ipython
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
Stars: ✭ 15,107 (+100613.33%)
Mutual labels:  repl
Alive Progress
A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
Stars: ✭ 2,940 (+19500%)
Mutual labels:  repl
Unrepl
A common ground for better Clojure REPLs
Stars: ✭ 222 (+1380%)
Mutual labels:  repl
dotnet-repl
A polyglot REPL built on .NET Interactive
Stars: ✭ 522 (+3380%)
Mutual labels:  repl
swiftreplmadness
Example of using your own packages in the Swift REPL
Stars: ✭ 18 (+20%)
Mutual labels:  repl
Mond
A scripting language for .NET Core
Stars: ✭ 237 (+1480%)
Mutual labels:  repl

Build Status Go Report Card codecov

Elasticsearch-cli

elasticsearch-cli provides a Kibana console-like interface to interact with ElasticSearch

Features

  • Cli interface, this is a one-off execution
  • Interactive console-like execution
  • REPL autocompletion
  • Persistent history
  • Authentication support

Installation

To install elasticsearch-cli you can either grab the latest binaries in the release page or install the latest and most recent commit from the source code

Latest build

elasticsearch-cli will be placed in ${GOPATH}/bin/elasticsearch-cli

git clone https://github.com/marclop/elasticsearch-cli
cd elasticsearch-cli
make install

Default configuration

There are a few configuration flags you can pass to elasticsearch-cli:

$ elasticsearch-cli --help
elasticsearch-cli provides a REPL console-like interface to interact with Elasticsearch

Usage:
  elasticsearch-cli [flags]
  elasticsearch-cli [command]

Available Commands:
  delete      Performs a DELETE operation against the remote endpoint
  get         Performs a GET operation against the remote endpoint
  head        Performs a HEAD operation against the remote endpoint
  help        Help about any command
  post        Performs a POST operation against the remote endpoint
  put         Performs a PUT operation against the remote endpoint
  version     prints the version

Flags:
      --cluster string      config name, used to have multiple clusters configured in $HOME/.elasticsearch-cli/<env> (default "default")
  -h, --help                help for elasticsearch-cli
      --host string         default elasticsearch URL (default "http://localhost")
  -p, --pass string         password to use to authenticate (If not specified, will look for ES_PASS environment variable)
      --poll-interval int   interval on which to poll Elasticsearch to provide index autocompletion (default 10)
      --port int            default elasticsearch port to use (default 9200)
  -t, --timeout int         http client timeout to the remote endpoint (default 10)
  -u, --user string         username to use to authenticate (If not specified look for ES_USER environment variable)
  -v, --verbose             enable verbose mode

Use "elasticsearch-cli [command] --help" for more information about a command.

Configuration Settings and Precedence

In order for elasticsearch-cli to be able to comunicate with an Elasticsearch cluster, it needs to have a set of configuration parameters set, which could either be defined in a configuration file, using environment variables or at runtime or using the cli's global flags. The hirearchy is as follows listed from higher precedence to lower:

  1. Command line flags (--host, --user, --pass, --verbose, etc).
  2. Environment variables.
  3. Shared configuration file ($HOME/.elasticsearch-cli/default.<json|toml|yaml|hcl>).

Configuration variables

Before you can start calling your Elasticsearch from the binary, you will need to configure it. Here's an example YAML configuration file ($HOME/.elasticsearch-cli/default.yaml) that will effectively point and configure the binary for Elastic Cloud:

host: https://9a980720ff16d55e3507bfc875551626.us-east-1.aws.found.io:9243
region: us-east-1
user: marc
pass: mypass

You could also specify the same settings using environment variables, or to override some settings of the YAML file, to do you'll need to prefix the configuration parameter with ES_ and capitalize the setting, i.e. ES_HOST or ES_USER.

export ES_CONFIG=mycluster

Last but not least, you can override any of the settings using the CLI flags.

elasticsearch-cli --config mycluster <COMMAND>

Multple configuration support

elasticsearch-cli supports the notion of having multiple cluster configuration files out of the box. It uses those to manage credentials and settings. By default it will use $HOME/.elasticsearch-cli/default.<json|toml|yaml|hcl>, but when the --config flag is specified, it will use the --config specified value as the file name inside $HOME/.elasticsearch-cli:

# Default behaviour
$ elasticsearch-cli version
Using config file: /Users/marc/.elasticsearch-cli/default.yaml
[...]

# when an environment is specified, the configuration file used will change
$ elasticsearch-cli version --config cluster
Using config file: /Users/marc/.elasticsearch-cli/cluster.yaml
[...]

Usage

elasticsearch-cli's usage is very intuitive, the execution is split between non-interactive and interactive, which is composed by 3 request arguments:

  1. Method
  2. URL
  3. Body

Non-interactive example:

$ elasticsearch-cli GET /
{
  "name": "GNBXbv5",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
$ elasticsearch-cli -verbose GET
Method:       GET
URL:          /
Response:     200 OK
Content-Type: application/json

{
  "name": "GNBXbv5",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
$ elasticsearch-cli GET _cat
=^.^=
/_cat/pending_tasks
/_cat/repositories
/_cat/segments
/_cat/segments/{index}
/_cat/health
/_cat/nodes
/_cat/allocation
/_cat/indices
/_cat/indices/{index}
/_cat/aliases
/_cat/aliases/{alias}
/_cat/templates
/_cat/plugins
/_cat/count
/_cat/count/{index}
/_cat/tasks
/_cat/nodeattrs
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}/_cat/master
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/snapshots/{repository}
/_cat/recovery
/_cat/recovery/{index}
/_cat/shards
/_cat/shards/{index}

Interactive mode

$ elasticsearch-cli -verbose
elasticsearch> GET
Method:       GET
URL:          /
Response:     200 OK
Content-Type: application/json

{
  "name": "GNBXbv5",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
elasticsearch> exit
$ elasticsearch-cli
elasticsearch> GET
Method:       GET
URL:          /

{
  "name": "GNBXbv5",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
elasticsearch> exit

Change configuration

While in interactive mode you an choose to change the application's configuration at any time:

$ elasticsearch-cli
elasticsearch> get
Method:       GET
URL:          /

{
  "name": "GNBXbv5",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
elasticsearch> set port 9201
elasticsearch> get
Method:       GET
URL:          /

{
  "name": "hIzXUZY",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "g5swow-2SHaCA6zPVvf1dQ",
  "version": {
    "number": "5.2.1",
    "build_hash": "db0d481",
    "build_date": "2017-02-09T22:05:32.386Z",
    "build_snapshot": false,
    "lucene_version": "6.4.1"
  },
  "tagline": "You Know, for Search"
}
elasticsearch> exit

Usage with jq

Of course if you feel like combining the power of Elasticsearch with jq for response filtering you can do so.

$ elasticsearch-cli GET | jq '.version.number'
"5.2.1"
$ elasticsearch-cli GET | jq '.name'
"GNBXbv5"
$ elasticsearch-cli -port 9201 GET | jq '.name'
"hIzXUZY"

Contributing

Setting up the environment

Elasticsearch-cli is written in Go, so you'll need the latest version of Golang if you want to contribute. You will also need the latest version of Docker to be able to run the acceptance tests.

Running all the tests

Issuing make test will run the combination of unit and acceptance tests. If you want a specific test, just use either target.

$ make test
-> Running unit tests for elasticsearch-cli...
ok  	github.com/marclop/elasticsearch-cli/app	0.010s	coverage: 33.3% of statements
ok  	github.com/marclop/elasticsearch-cli/cli	0.015s	coverage: 63.9% of statements
ok  	github.com/marclop/elasticsearch-cli/client	0.027s	coverage: 83.3% of statements
?   	github.com/marclop/elasticsearch-cli/elasticsearch	[no test files]
ok  	github.com/marclop/elasticsearch-cli/poller	0.008s	coverage: 81.5% of statements
ok  	github.com/marclop/elasticsearch-cli/utils	0.006s	coverage: 100.0% of statements
?   	github.com/marclop/elasticsearch-cli	[no test files]
-> Installing elasticsearch-cli dependencies...
[..]
-> Building elasticsearch-cli...
Number of parallel builds: 7

-->    darwin/amd64: github.com/marclop/elasticsearch-cli
=> Starting Elasticsearch 1.7... Done.
-> Running acceptance tests for elasticsearch-cli in Elasticsearch 1.7...
ok  	github.com/marclop/elasticsearch-cli	1.276s
-> Killing Docker container elasticsearch-cli_es_1.7
=> Starting Elasticsearch 2.4... Done.
-> Running acceptance tests for elasticsearch-cli in Elasticsearch 2.4...
ok  	github.com/marclop/elasticsearch-cli	1.421s
-> Killing Docker container elasticsearch-cli_es_2.4
=> Starting Elasticsearch 5.4... Done.
-> Running acceptance tests for elasticsearch-cli in Elasticsearch 5.4...
ok  	github.com/marclop/elasticsearch-cli	3.566s
-> Killing Docker container elasticsearch-cli_es_5.4

SEE ALSO

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].