blackbean

The blackbean is a command tool for elasticsearch operations by using cobra. Besides, blackbean is the name of my lovely French bulldog.

1. Start to enjoy blackbean

curl -LO https://github.com/toughnoah/blackbean/releases/download/v1.0.2/blackbean
chmod +x ./blackbean
mv ./blackbean /usr/local/bin
git clone -b master [email protected]:toughnoah/blackbean.git
cd blackbean
make

2. Configuration

Define your config .blackbean.yaml file firstly and put it into your home directory, do not forget specify current as one of your cluster.

cluster:
  prod:
    url: https://a.es.com:9200
    username: Noah
    password: abc
  qa:
    url: https://b.es.com:9200
    username: Noah
    password: abc
current: qa

3. Shell completion

All commands have fulfilled necessary completion, including flags. Enjoy yourself with blackbean!

[[email protected] ~]# echo "source <(blackbean completion bash)" >> ~/.bashrc
[[email protected] ~]# blackbean [tab][tab]
alias       cat         current-es  help        repo        role        use         watcher
apply       completion  explain     index       reroute     snapshot    user

[[email protected] ~]# blackbean cat [tab][tab]
allocations   cachemem      health        largeindices  nodes         segmem        threadpoo

4. Common Flag

You can use -d or --data to specify raw request body like '{"query":"match_all":{}}'.
Also, you can directly read from file using -f or --filename. Both json and yaml are supported.

[[email protected] ~]# blackbean index search test-* --
--config     --config=    --data       --data=      --filename   --filename=
[[email protected] ~]# cat query.json
{"size":1,
  "query":{
"match_all": {}}}

5. Command

[[email protected] ~]# blackbean
blackbean command provides a set of commands to talk with es via cli.
Besides, blackbean is the name of my favorite french bulldog.

Usage:
  blackbean [command]

Available Commands:
  alias       alias index
  apply       apply cluster changes
  cat         cat allocation/nodes/health/nodes/threadpool/cache memory/segments memory/large indices.
  completion  Generate completion script
  current-es  show current cluster context
  explain     explain index allocation
  help        Help about any command
  index       index operations
  repo        repo operations
  reroute     reroute for cluster
  role        role operations for cluster
  snapshot    snapshot operations
  use         change current cluster context
  user        user for cluster
  watcher     operate watcher

Flags:
      --config string   config file (default is $HOME/.blackbean.yaml)
  -h, --help            help for blackbean
  -t, --toggle          Help message for toggle

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

5.1. Current es

[[email protected] ~]# blackbean current-es
current using cluster: qa

5.2. Use

[[email protected] ~]# blackbean use [tab][tab]
prod  qa
[[email protected] ~]# blackbean use qa
change to cluster: qa

5.3. Cat

[[email protected] ~]# blackbean cat health 
[200 OK] epoch      timestamp cluster       status node.total node.data shards  pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1624371902 14:25:02  black-cluster green          12         9   9304 4652    0    0        0             0                  -                100.0%

5.4. Apply

[[email protected] ~]# blackbean apply settings -e
null       primaries
[[email protected] ~]# blackbean apply
apply cluster changes ... wordless

Usage:
  blackbean apply [command]

Available Commands:
  clearCache  apply indices to clear cache
  flush       apply indices to flush
  settings    apply cluster settings change

Flags:
  -h, --help   help for apply

Global Flags:
      --config string   config file (default is $HOME/.blackbean.yaml)

Use "blackbean apply [command] --help" for more information about a command.
[[email protected] ~]# blackbean apply settings -h
apply cluster settings ... wordless

Usage:
  blackbean apply [resource] [flags]

Flags:
  --allocation_enable string                   to set allocation enable value, primaries or null
  --breaker_fielddata string                   to set breaker_fielddata value, such as 60%
  --breaker_request string                     to set breaker_request value, such as 60%
  --breaker_total string                       to set breaker_total value, such as 60%
  --cluster_concurrent_rebalanced string       to set cluster_concurrent_rebalanced value, such as 10
  --help                                       help for apply
  --max_bytes_per_sec string                   to set indices recovery max_bytes_per_sec, default 40
  --max_compilations_rate string               to set max_compilations_rate value, such as 75/5m
  --max_shards_per_node string                 to set max_shards_per_node value, such as 1000
  --node_concurrent_recoveries string          to set node_concurrent_recoveries value, such as 10
  --node_initial_primaries_recoveries string   to set node_initial_primaries_recoveries value, such as 10
  --watermark_high string                      to set watermark_high value, such as 85%
  --watermark_low string                       to set watermark_low value, such as 90%

Global Flags:
  -c, --cluster string   to specify a es cluster (default "default")
      --config string    config file (default is $HOME/.blackbean.yaml)

5.5. Repo

[[email protected] ~]# blackbean repo
repo operations ... wordless

Usage:
  blackbean repo [command]

Available Commands:
  create      create specific snapshots
  delete      delete specific snapshots
  get         get specific repository

Flags:
  -h, --help   help for repo

Global Flags:
      --config string   config file (default is $HOME/.blackbean.yaml)

Use "blackbean repo [command] --help" for more information about a command.

5.6. Snapshot

[[email protected] ~]# blackbean snapshot
snapshot operations ... wordless

Usage:
  blackbean snapshot [command]

Available Commands:
  create      create specific snapshots
  delete      delete specific snapshots
  get         get specific snapshots
  restore     get specific index to restore

Flags:
  -h, --help   help for snapshot

Global Flags:
      --config string   config file (default is $HOME/.blackbean.yaml)

Use "blackbean snapshot [command] --help" for more information about a command.

5.7. Index

[[email protected] ~]# blackbean index
index operations ... wordless

Usage:
  blackbean index [command]

Available Commands:
  bulk        send bulk request
  create      create index from command
  delete      delete index from command
  get         get index from cluster
  msearch     send msearch request
  reindex     do reindex
  search      search index from cluster
  write       write index from command
...
[[email protected] ~]# blackbean index msearch -h
send msearch request ... wordless

Usage:
  blackbean index msearch [flags]

Flags:
  -d, --data string                         the path to raw file with request body (default "{}")
  -h, --help                                help for msearch
      --max_concurrent_searches int         ID of the pipeline to use to preprocess incoming documents.
      --max_concurrent_shard_requests int   if true, the request’s actions must target an index alias.
      --raw_file string                     the path to raw file with request body
[[email protected] ~]# blackbean index search test-* -f query.json
[200 OK] {
  "took" : 172,
  "timed_out" : false,
  ...
[[email protected] ~]# blackbean index search test-* -f query.yaml
[200 OK] {
  "took" : 172,
  "timed_out" : false,
  ...
[[email protected] ~]# blackbean index search test-* -d '{"query":{"match_all":{}}}'
[200 OK] {
  "took" : 172,
  "timed_out" : false,
  ...
[[email protected] ~]# blackbean index get test-2021.06
[200 OK] {
  "test-2021.06" : {
    ...

5.8. Alias

[[email protected] ~]# blackbean alias
alias index ... wordless

Usage:
  blackbean alias [command]

Available Commands:
  create      create alias for index
  delete      delete alias for index
  get         get alias for index or get alias list

...

5.9. Reroute

[[email protected] ~]# blackbean reroute
reroute for cluster ... wordless

Usage:
  blackbean reroute [command]

Available Commands:
  allocateReplicas allocate replicas index
  cancel           cancel allocating index
  failed           retry failed allocation
  move             move index
...

5.10. User

[[email protected] ~]# blackbean user
user for cluster ... wordless

Usage:
  blackbean user [command]

Available Commands:
  create      create specify user
  delete      delete specify user
  get         get specify user
  update      update specify user
...

5.11. Role

[[email protected] ~]# blackbean role
role operations for cluster ... wordless

Usage:
  blackbean role [command]

Available Commands:
  create      create specify user
  delete      delete specify role
  get         get specify role
  update      update specify user
...


5.12. Explain

[[email protected] ~]# blackbean explain -h
explain index allocation ... wordless

Usage:
  blackbean explain [index] [flags]

Flags:
      --current_node string   specifies the node ID or the name of the node to only explain a shard that is currently located on the specified node.
  -h, --help                  help for explain
      --primary               if true, returns explanation for the primary shard for the given shard ID.
      --shard string          specifies the ID of the shard that you would like an explanation for.
...

5.13. Template

[[email protected] ~]# blackbean template
template operations ... wordless

Usage:
  blackbean template [command]

Available Commands:
  apply       create or update template
  delete      delete or update template
  get         get template
...

5.14. Watcher

[[email protected] ~]# blackbean watcher
operate watcherr ... wordless

Usage:
  blackbean watcher [command]

Available Commands:
  start       start watcher
  stats       get watcher stats
  stop        stop watcher
...

6. Contact Me

Any advice is welcome! Please email to [email protected]

GitHub

https://github.com/toughnoah/blackbean