Dec 1st, 2026: [EN] The 12 days of Peek: 12 features of an interactive Elasticsearch CLI

Ce post est également disponible en français

Welcome to the Elastic Advent Calendar! Today, we're going to talk about Peek, an interactive CLI tool to explore an Elasticsearch instance.

While an Elastic employee maintains Peek, it's not an official Elastic product. It's also very different from the official Elastic CLI, which is meant for scripts and agents, not interactive human use. With that out of the way, let the fun begin!

To make things more interesting, we'll reuse the structure of The Twelve Days of Christmas, with illustrations from Xavier Romero-Frias (CC BY-SA 3.0).

If you want to follow along, use start-local to start Elasticsearch (and Kibana):

$ curl -fsSL https://elastic.co/start-local | sh

  ______ _           _   _
 |  ____| |         | | (_)
 | |__  | | __ _ ___| |_ _  ___
 |  __| | |/ _` / __| __| |/ __|
 | |____| | (_| \__ \ |_| | (__
 |______|_|\__,_|___/\__|_|\___|
-------------------------------------------------
🚀 Run Elasticsearch and Kibana for local testing
-------------------------------------------------

ℹ️  Do not use this script in a production environment

⌛️ Setting up Elasticsearch and Kibana v9.5.7-arm64...

- Generated random passwords
- Created the elastic-start-local folder containing the files:
  - .env, with settings
  - docker-compose.yml, for Docker services
  - start/stop/uninstall commands
- Running docker compose up --wait

[...]

🎉 Congrats, Elasticsearch and Kibana are installed and running in Docker!

🌐 Open your browser at http://localhost:5601

   Username: elastic
   Password: [redacted]

🔌 Elasticsearch API endpoint: http://localhost:9200
🔑 API key: [redacted]

Learn more at https://github.com/elastic/start-local

On the first day of Christmas, Peek gave to me: a Kibana-like Console in my terminal

You can install Peek directly from PyPI, using your favorite package manager. I recommend installing it as a tool with uv:

uv tool install es-peek

Now, start Peek, which will prompt you for your password: enter the one you got from start-local.

$ peek --hosts localhost:9200 --username elastic
Please enter password: ********

You can now send your first command. Blank line (or ESC+Enter) confirms.

>>> [0] elastic @ http://localhost:9200
GET /

=== took=9.952ms
{
  "name": "e7e408a664c9",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "PDEH2qiNQ8SlJltrSh1TRg",
  "version": {
    "number": "9.5.7",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "d16690c781d994379d7d7be885c266543c2f6991",
    "build_date": "2026-11-19T00:34:54.990835033Z",
    "build_snapshot": false,
    "lucene_version": "10.5.2",
    "minimum_wire_compatibility_version": "8.19.0",
    "minimum_index_compatibility_version": "8.0.0"
  },
  "tagline": "You Know, for Search"
}

On the second day: two modes of running

We've already seen the first mode of running: interactive queries. But Peek also supports batch mode:

  • Inside a session, you can type run 'setup.es' to run a script containing queries.
  • You can also directly run peek --username elastic setup.es or cat setup.es | peek --username elastic

On the third day: three kinds of quotes

Since Peek is meant mostly for human use, not scripts, it is flexible with quotes. You can use single quotes and double quotes:

// Index a single document
POST /my-index/_doc/1
{'foo': "bar"}  // both single and double quotes are acceptable

More importantly, triple quotes are also allowed, which improves readability for characters that are usually escaped in JSON. They also improve compatibility with the Kibana Console, which supports them too.

// Execute an ES|QL query (triple quotes can be either ''' or """)
POST /_query?format=txt
{
  "query": """
    FROM my-index
    | WHERE foo == "bar"
    | LIMIT 10
  """
}

Additionally, Peek also allows // comments, trailing commas, and lowercase verbs:

>>> [0] elastic @ http://localhost:9200
post /_query?format=txt
{"query": "FROM my-index | LIMIT 10",} // trailing comma
=== took=12.950ms
      foo      |  foo.keyword
---------------+---------------
bar            |bar

On the fourth day: four calling options

Peek documents four options on the query line:

// Run-AS and other headers
GET _security/_authenticate runas='foo' xoid='my-x-opaque-id' headers={'some-other-header': 'blah'}
// Choose a specific connection
get / conn=0  // send the request to the first connection (zero-based index)

See the connections docs for more details.

On the fifth day: five golden keyrings

OK, not actually five: one keyring is enough. Peek keeps your password in the system keyring on major operating systems, so you don't have to type it twice. If it changed, use --force_prompt to update it.

On the sixth day: six shortcuts a-saving

Peek supports most readline shortcuts such as Ctrl-a, Ctrl-k, Ctrl-r, and documents six shortcuts:

  • <F3> - toggle formatting
  • <F12> - toggle mouse support
  • ESC + Enter - send the request
  • ESC + c - Copy current input to system clipboard (this requires installing es-peek[full]).
  • ESC + a - Go to the beginning of the current input buffer
  • ESC + e - Go to the end of the current input buffer

On the seventh day: seven ways of signing in

Peek supports:

Fun fact: if you create an API key within Peek, type connect to use it from now on!

PUT _security/api_key
{"name": "advent-key"}

connect

On the eighth day: eight clusters connected

You can connect to as many clusters as you want thanks to Peek's connection support:

connect hosts='localhost:9200' username='elastic'
connection rename='local'
connection        // list them all
get / conn=0      // ask the first one without switching
session @save     // keep them for next time

On the ninth day: nine-dot-x completions

Run _download_api_specs to get 9.x autocompletion thanks to the Elasticsearch specification. On an 8.x cluster, set autocompletion_version = 8.19 in peekrc first.

On the tenth day: ten thousand history entries

Peek keeps 10,000 history entries in an SQLite database. Ctrl-r works, but you can also use history to list past commands and history 42 to run the 42nd entry.

On the eleventh day: eleven pipers piping

Peek can run commands on responses with pipe or store the result in a file with out:

GET / pipe='jq .version.number'
GET /_cat/indices out='indices.txt'
!wc -l indices.txt

@ allows loading a payload from an NDJSON file:

POST /gifts/_bulk
@gifts.ndjson

On the twelfth day: twelve docs a-drumming

Finally, Peek has a small scripting language! See it in action:

for i in range(0, 12) {
  PUT ("drummers/_doc/" + i)
  { "drummer": i, "bpm": randint(60, 180) }
}
GET drummers/_doc/11
echo _."_source"."bpm"

(_ holds the last response.)

All together now

On the twelfth day of Christmas, Peek gave to me:
twelve docs a-drumming,
eleven pipers piping,
ten thousand history entries,
nine-dot-x completions,
eight clusters connected,
seven ways of signing in,
six shortcuts a-saving,
five golden keyrings,
four calling options,
three kinds of quotes,
two modes of running,
and a Kibana-like Console in my terminal.

And if twelve gifts are not enough, extend Peek with your own gifts:

  • Save this as ~/.config/peek/extensions/hello.py:

    def hello(app):
        return "Hello!"
    
    EXPORTS = {'hello': hello}
    
  • Start Peek and type hello.

Type help to see everything, and read more in the documentation.

Happy holidays, and happy peeking!

5 Likes