Type to search.

Set up shell completion for the Elastic CLI

Serverless Preview

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Preview

    This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack Preview

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Preview

    This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

elastic completion <shell> prints a wrapper script that hooks the CLI into your shell's tab-completion system. Bash, Zsh, Fish, and PowerShell are supported.

The wrapper is dynamic: each <tab> shells out to elastic to ask which candidates apply, so completions stay in sync with the installed CLI version and include context names from your config file.

Shell
# System-wide (writable by root):
elastic completion bash | sudo tee /etc/bash_completion.d/elastic > /dev/null

# Per-user (no sudo required):
mkdir -p ~/.local/share/bash-completion/completions
elastic completion bash > ~/.local/share/bash-completion/completions/elastic

Then open a new shell.

Shell
# Drop the script into the first directory in $fpath:
elastic completion zsh > "${fpath[1]}/_elastic"

# Make sure compinit is enabled in ~/.zshrc:
autoload -Uz compinit && compinit

Or, for a one-shot install in the current session:

Shell
eval "$(elastic completion zsh)"
Fish
elastic completion fish > ~/.config/fish/completions/elastic.fish

Fish picks up new completion files automatically.

Powershell
elastic completion powershell | Out-File -Encoding utf8 -Append $PROFILE

Then open a new PowerShell session.

  • Top-level commands and groups (stack, cloud, docs, config, …)
  • Nested subcommands at every depth
  • Long option flags (--json, --use-context, command-specific options)
  • Context names for --use-context (read from the active config file)
  • The es / kb aliases work identically to the canonical stack es / stack kb forms

Completion respects the active commands.allowed / commands.blocked policy: commands you have restricted yourself out of do not appear as candidates.