Extend 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
Extensions add new top-level subcommands to the CLI. Once installed, an extension named demo is invoked as elastic demo.
# from a GitHub repository (github:owner/repo or shorthand owner/repo)
elastic extension install github:elastic/elastic-demo
elastic extension install elastic/elastic-demo
# from an npm package
elastic extension install npm:elastic-demo
The CLI clones or installs the extension into ~/.elastic/extensions/elastic-<name>/, discovers the entrypoint from the package.json bin field, and registers it. If the repository includes a package.json, npm install --production is run automatically after cloning.
extension create scaffolds a new extension and registers it in one step. It is the quickest way to start writing your own extension.
# create a fresh extension at ~/.elastic/extensions/elastic-my-tool/
elastic extension create my-tool
# register an existing directory as a local extension (files are not overwritten)
elastic extension create demo --path ./path/to/my-extension
The scaffolded index.js is a runnable starting point that outputs JSON with the current context. Edit it to implement real logic.
The CLI passes the selected context to every extension via environment variables before spawning it:
| Variable | Description |
|---|---|
ELASTIC_ES_URL |
Elasticsearch URL from the selected context |
ELASTIC_ES_API_KEY |
Elasticsearch API key |
ELASTIC_ES_USERNAME |
Elasticsearch username, when the context uses basic authentication |
ELASTIC_ES_PASSWORD |
Elasticsearch password, when the context uses basic authentication |
ELASTIC_KIBANA_URL |
Kibana URL |
ELASTIC_KIBANA_API_KEY |
Kibana API key |
ELASTIC_KIBANA_USERNAME |
Kibana username, when the context uses basic authentication |
ELASTIC_KIBANA_PASSWORD |
Kibana password, when the context uses basic authentication |
ELASTIC_CLOUD_URL |
Elastic Cloud API URL |
ELASTIC_CLOUD_API_KEY |
Elastic Cloud API key |
The selected context is the current context unless you choose another one. Put the global --config-file, --use-context, and --command-profile options before the extension name, or put the context options directly after it, before the extension's own arguments:
elastic --use-context staging demo
elastic demo --use-context staging
The CLI forwards everything from the extension's first own argument, or from --, to the extension untouched.
# list installed extensions
elastic extension list
# upgrade one extension (github and npm sources only)
elastic extension upgrade my-tool
# upgrade all extensions
elastic extension upgrade
# remove an extension
elastic extension remove my-tool
The examples/extensions/basic/ directory in the CLI repository contains a minimal working example. Register it locally with:
elastic extension create demo --path ./examples/extensions/basic
elastic demo