From aa9a96f327fb0c1d09ac93ab02af4c33687c710a Mon Sep 17 00:00:00 2001 From: Fedele Mantuano Date: Mon, 24 Aug 2015 12:17:06 +0200 Subject: [PATCH 1/4] Added GET API Elasticsearch plugin Manage _cat API Added PUT, POST, DELETE commands. Added options for autocomplete --- plugins/elasticsearch/_GET | 28 ++++++++++++ .../elasticsearch/elasticsearch.plugin.zsh | 45 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 plugins/elasticsearch/_GET create mode 100644 plugins/elasticsearch/elasticsearch.plugin.zsh diff --git a/plugins/elasticsearch/_GET b/plugins/elasticsearch/_GET new file mode 100644 index 000000000..7fe4842d9 --- /dev/null +++ b/plugins/elasticsearch/_GET @@ -0,0 +1,28 @@ +#compdef GET + +local -a options +options=( + '_cache/clear:Allows to clear all caches for all indices' + '_cluster/health:Cluster status health' + '_cluster/nodes/_local/_shutdown:Shutdown local node' + '_cluster/pending_tasks:Returns a list of any cluster-level changes which have not yet been executed' + '_cluster/settings:Cluster settings' + '_cluster/state:Allows to get a comprehensive state information of the whole cluster' + '_cluster/stats:Allows to retrieve statistics from a cluster wide perspective' + '_flush:Allows to flush all indices' + '_nodes/hot_threads:Allowing to get the current hot threads on each node in the cluster' + '_nodes/stats/indices:Field data memory usage on node level' + '_nodes/stats:Allows to retrieve all of the cluster nodes statistics' + '_nodes:Allows to retrieve all of the cluster nodes information' + '_optimize?max_num_segments=1:Allows to optimize all indices' + '_recovery:Cluster-wide recovery status' + '_recovery?detailed=true:Cluster-wide recovery status with details' + '_refresh:Allows to explicitly refresh all indices' + '_segments:Include segments for all indices' + '_shutdown:Shutdown all nodes' + '_stats/fielddata:Field data memory usage on index level' + '_stats:High level aggregation and index level stats for all indices' + '_status:Status information of all indices' + '_template:List of all index templates' +) +_describe 'values' options diff --git a/plugins/elasticsearch/elasticsearch.plugin.zsh b/plugins/elasticsearch/elasticsearch.plugin.zsh new file mode 100644 index 000000000..aa97f80a7 --- /dev/null +++ b/plugins/elasticsearch/elasticsearch.plugin.zsh @@ -0,0 +1,45 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# You can use Elastichsearch GET API like in Marvel sense console: +# GET / +# GET _cluster/health +# GET _nodes/stats +# GET _stats/fielddata?fields=* +# GET _nodes/stats/indices/fielddata?fields=* +# +# You have do install json_reformat (http://dev.man-online.org/package/main/yajl-tools/) +# to format json +# +# ------------------------------------------------------------------------------ +# Author +# ------- +# +# * Fedele Mantuano (Twitter: @fedelemantuano) +# +# ------------------------------------------------------------------------------ + +alias ech='GET _cluster/health' +alias ecs='GET _cluster/state' +alias ens='GET _nodes/stats' +alias esf='GET _stats/fielddata' + +# GET +if which json_reformat > /dev/null 2>&1; then + GET() { curl -s -XGET http://localhost:9200/"$@" | json_reformat 2>/dev/null || curl -s -XGET http://localhost:9200/"$@" } +else + GET() { curl -s -XGET http://localhost:9200/"$@" } +fi + +# HEAD +HEAD() { curl -s -XHEAD -i http://localhost:9200/"$@" } + +# DELETE +DELETE() { curl -s -XDELETE http://localhost:9200/"$@" } + +# PUT +PUT() { curl -s -XPUT http://localhost:9200/"$@" } + +# POST +POST() { curl -s -XPOST http://localhost:9200/"$@" } From bdf5147632b9eaa31639704120dc5c3b0e72fe3f Mon Sep 17 00:00:00 2001 From: Fedele Mantuano Date: Mon, 31 Aug 2015 17:09:40 +0200 Subject: [PATCH 2/4] Added README.md --- plugins/elasticsearch/README.md | 18 ++++++++++++++++++ plugins/elasticsearch/_GET | 1 + 2 files changed, 19 insertions(+) create mode 100644 plugins/elasticsearch/README.md diff --git a/plugins/elasticsearch/README.md b/plugins/elasticsearch/README.md new file mode 100644 index 000000000..2fae0a68c --- /dev/null +++ b/plugins/elasticsearch/README.md @@ -0,0 +1,18 @@ +elasticsearch +======= +This plugin makes easy to use Elasticsearch API and it also offering autocomplete for common APIs. +There are `GET`, `HEAD`, `DELETE`, `PUT` and `POST` commands. + +Examples usage: +- `GET _cluster/health` +- `GET _cat` +- `DELETE twitter` + + +Aliases +------- + +- `alias ech='GET _cluster/health'`: Cluster status health +- `alias ecs='GET _cluster/state'`: Allows to get a comprehensive state information of the whole cluster +- `alias ens='GET _nodes/stats'`: Allows to retrieve all of the cluster nodes statistics +- `alias esf='GET _stats/fielddata'`: Field data memory usage on index level diff --git a/plugins/elasticsearch/_GET b/plugins/elasticsearch/_GET index 7fe4842d9..aad95d43e 100644 --- a/plugins/elasticsearch/_GET +++ b/plugins/elasticsearch/_GET @@ -3,6 +3,7 @@ local -a options options=( '_cache/clear:Allows to clear all caches for all indices' + '_cat:List of all cat commands' '_cluster/health:Cluster status health' '_cluster/nodes/_local/_shutdown:Shutdown local node' '_cluster/pending_tasks:Returns a list of any cluster-level changes which have not yet been executed' From e806b1ae6079652273d16f67059b8fc81828554f Mon Sep 17 00:00:00 2001 From: Fedele Mantuano Date: Fri, 4 Sep 2015 22:27:57 +0200 Subject: [PATCH 3/4] Moved comments in README.md --- plugins/elasticsearch/README.md | 15 ++++++++++++- .../elasticsearch/elasticsearch.plugin.zsh | 22 ------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/plugins/elasticsearch/README.md b/plugins/elasticsearch/README.md index 2fae0a68c..d9c89c672 100644 --- a/plugins/elasticsearch/README.md +++ b/plugins/elasticsearch/README.md @@ -1,13 +1,21 @@ elasticsearch ======= This plugin makes easy to use Elasticsearch API and it also offering autocomplete for common APIs. -There are `GET`, `HEAD`, `DELETE`, `PUT` and `POST` commands. +There are [`GET`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html), +[`HEAD`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html), +[`DELETE`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html), +[`PUT`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html) and +[`POST`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html) commands. Examples usage: - `GET _cluster/health` +- `GET _nodes/stats` +- `GET _stats/fielddata?fields=*` +- `GET _nodes/stats/indices/fielddata?fields=*` - `GET _cat` - `DELETE twitter` +You should install [`json_reformat`](http://dev.man-online.org/package/main/yajl-tools/) to format json output. Aliases ------- @@ -16,3 +24,8 @@ Aliases - `alias ecs='GET _cluster/state'`: Allows to get a comprehensive state information of the whole cluster - `alias ens='GET _nodes/stats'`: Allows to retrieve all of the cluster nodes statistics - `alias esf='GET _stats/fielddata'`: Field data memory usage on index level + +Author +------- + +Fedele Mantuano (**Twitter**: [@fedelemantuano](https://twitter.com/fedelemantuano)) diff --git a/plugins/elasticsearch/elasticsearch.plugin.zsh b/plugins/elasticsearch/elasticsearch.plugin.zsh index aa97f80a7..60dc0e05f 100644 --- a/plugins/elasticsearch/elasticsearch.plugin.zsh +++ b/plugins/elasticsearch/elasticsearch.plugin.zsh @@ -1,25 +1,3 @@ -# ------------------------------------------------------------------------------ -# Description -# ----------- -# -# You can use Elastichsearch GET API like in Marvel sense console: -# GET / -# GET _cluster/health -# GET _nodes/stats -# GET _stats/fielddata?fields=* -# GET _nodes/stats/indices/fielddata?fields=* -# -# You have do install json_reformat (http://dev.man-online.org/package/main/yajl-tools/) -# to format json -# -# ------------------------------------------------------------------------------ -# Author -# ------- -# -# * Fedele Mantuano (Twitter: @fedelemantuano) -# -# ------------------------------------------------------------------------------ - alias ech='GET _cluster/health' alias ecs='GET _cluster/state' alias ens='GET _nodes/stats' From 9b983f3c6bb819b4da03ed3cae52c6cefb5df57c Mon Sep 17 00:00:00 2001 From: Fedele Mantuano Date: Wed, 30 Mar 2016 01:58:26 +0200 Subject: [PATCH 4/4] Added environment variable to change client node to query --- plugins/elasticsearch/README.md | 11 ++++++++++- plugins/elasticsearch/_GET | 1 - plugins/elasticsearch/elasticsearch.plugin.zsh | 16 ++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/elasticsearch/README.md b/plugins/elasticsearch/README.md index d9c89c672..2c398893d 100644 --- a/plugins/elasticsearch/README.md +++ b/plugins/elasticsearch/README.md @@ -1,4 +1,4 @@ -elasticsearch +Elasticsearch ======= This plugin makes easy to use Elasticsearch API and it also offering autocomplete for common APIs. There are [`GET`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html), @@ -17,6 +17,15 @@ Examples usage: You should install [`json_reformat`](http://dev.man-online.org/package/main/yajl-tools/) to format json output. +Instructions +------- + +If you'd prefer to specify an explicit Elasticsearch node client to query, you can set variable like so in `.zshrc`: + +`export CLIENT_ELK_NODE=client_node` + +Default is `localhost`. + Aliases ------- diff --git a/plugins/elasticsearch/_GET b/plugins/elasticsearch/_GET index aad95d43e..a08ec8e33 100644 --- a/plugins/elasticsearch/_GET +++ b/plugins/elasticsearch/_GET @@ -23,7 +23,6 @@ options=( '_shutdown:Shutdown all nodes' '_stats/fielddata:Field data memory usage on index level' '_stats:High level aggregation and index level stats for all indices' - '_status:Status information of all indices' '_template:List of all index templates' ) _describe 'values' options diff --git a/plugins/elasticsearch/elasticsearch.plugin.zsh b/plugins/elasticsearch/elasticsearch.plugin.zsh index 60dc0e05f..4045c2710 100644 --- a/plugins/elasticsearch/elasticsearch.plugin.zsh +++ b/plugins/elasticsearch/elasticsearch.plugin.zsh @@ -3,21 +3,25 @@ alias ecs='GET _cluster/state' alias ens='GET _nodes/stats' alias esf='GET _stats/fielddata' +if [ -z ${CLIENT_ELK_NODE} ]; then + export CLIENT_ELK_NODE=localhost +fi + # GET if which json_reformat > /dev/null 2>&1; then - GET() { curl -s -XGET http://localhost:9200/"$@" | json_reformat 2>/dev/null || curl -s -XGET http://localhost:9200/"$@" } + GET() { curl -s -XGET http://${CLIENT_ELK_NODE}:9200/"$@" | json_reformat 2>/dev/null || curl -s -XGET http://${CLIENT_ELK_NODE}:9200/"$@" } else - GET() { curl -s -XGET http://localhost:9200/"$@" } + GET() { curl -s -XGET http://${CLIENT_ELK_NODE}:9200/"$@" } fi # HEAD -HEAD() { curl -s -XHEAD -i http://localhost:9200/"$@" } +HEAD() { curl -s -XHEAD -i http://${CLIENT_ELK_NODE}:9200/"$@" } # DELETE -DELETE() { curl -s -XDELETE http://localhost:9200/"$@" } +DELETE() { curl -s -XDELETE http://${CLIENT_ELK_NODE}:9200/"$@" } # PUT -PUT() { curl -s -XPUT http://localhost:9200/"$@" } +PUT() { curl -s -XPUT http://${CLIENT_ELK_NODE}:9200/"$@" } # POST -POST() { curl -s -XPOST http://localhost:9200/"$@" } +POST() { curl -s -XPOST http://${CLIENT_ELK_NODE}:9200/"$@" }