Set up shell completion for the Elastic CLI
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability 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. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability 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.
Serverless
Preview
Preview
Stack
Preview
Preview
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.
# 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.
# 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:
eval "$(elastic completion zsh)"
elastic completion fish > ~/.config/fish/completions/elastic.fish
Fish picks up new completion files automatically.
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/kbaliases work identically to the canonicalstack es/stack kbforms
Completion respects the active commands.allowed / commands.blocked policy: commands you have restricted yourself out of do not appear as candidates.