Elasticsearch / OpenSearch ops
v0.1.21Cluster + index introspection plus narrow mutators (cache_clear, force_merge, flush, close_index). Auth via ELASTIC_USER + ELASTIC_PASSWORD env vars on the runner host. Does NOT include delete_index — too easy to misuse.
curl
bash
Install
emisar pack install
fetches this pack, re-validates it, and verifies its content hash against the
--hash
below — the exact bytes this page was rendered against, so a tampered copy is
rejected — before copying it into the runner's packs dir. The command reloads a
running daemon itself; no manual restart.
sudo emisar pack install elasticsearch --hash sha256:159be18e8b70759503205ef5e3c9789ccd5e569ccd4959e36552064bdd8f9972
Setup
Each action reaches the cluster at
ELASTIC_URL
with curl. When
ELASTIC_USER
is set,
ELASTIC_USER
and
ELASTIC_PASSWORD
become an HTTP Basic
Authorization
header piped to curl on stdin, so the credential never reaches the command line or a
ps
listing.
Environment
Set these on the runner host, then add each name to
execution.inherit_env
so the value reaches the action.
-
ELASTIC_URLdefault http://127.0.0.1:9200Base URL of the cluster, scheme and port included. Defaults to a local node.
-
ELASTIC_USERUsername for HTTP basic auth; needs privileges for the actions you enable. Leave unset for a cluster with security disabled.
-
ELASTIC_PASSWORDPassword for
ELASTIC_USER.
Notes
- Create the user in Kibana under Stack Management → Security → Users, or with bin/elasticsearch-users useradd on a self-managed node. The reads need the monitor cluster privilege plus read on the target indices.
-
Whichever of these you set must also be allowlisted in the runner's
inherit_env— the action env is scrubbed to PATH/LANG/LC_ALL/TERM by default, so a variable present on the host but not inherited is silently dropped. -
A cluster without security enabled needs no placeholder credential: leave
ELASTIC_USERunset and noAuthorizationheader is sent. - Mutators (cache_clear, force_merge, flush, close_index) need a role with manage privileges on the target indices.
Verify it works
Runs es.cluster_health, a low-risk
read that confirms the pack can reach its target. Run it on the host once the pack
is installed; pack install runs it for
you.
sudo emisar pack verify elasticsearch
Install and configure a pack walks through the whole sequence on a host.
Actions 21 total
View on GitHub-
es.cache_clear script high High — service-affecting
POST /<index>/_cache/clear
Clear caches (request, query, fielddata) on one index. Next queries pay the cold-cache cost.
View source on GitHub -
es.cat_aliases script low Low — read-only or trivially reversible
GET /_cat/aliases
List all aliases pointing to indices. Use to confirm an alias rotation worked.
View source on GitHub -
es.cat_indices script low Low — read-only or trivially reversible
GET /_cat/indices
List every index with its primary count, doc count, store size. Sorted by size descending.
View source on GitHub -
es.cat_nodes script low Low — read-only or trivially reversible
GET /_cat/nodes
List nodes with heap, RAM, CPU, load, role. Read-only.
View source on GitHub -
es.cat_recovery script low Low — read-only or trivially reversible
GET /_cat/recovery
List active shard recoveries (peer, snapshot). Use to monitor rebalance progress.
View source on GitHub -
es.cat_segments script low Low — read-only or trivially reversible
GET /_cat/segments
Show per-segment doc + bytes counts. Use to plan a force_merge.
View source on GitHub -
es.cat_shards script low Low — read-only or trivially reversible
GET /_cat/shards
List every shard with state (STARTED/UNASSIGNED/INITIALIZING/RELOCATING) and node. Sorted by store size.
View source on GitHub -
es.cat_thread_pool script low Low — read-only or trivially reversible
GET /_cat/thread_pool
Show per-node thread pool queue + rejection counts. Use to spot search/write thread saturation.
View source on GitHub -
es.close_index script critical Critical — data loss or irreversible
POST /<index>/_close
Close one index — it becomes unsearchable and unwritable, but stays on disk. Use to "archive" old logs without deleting. Reverse with /_open. **Closed indices count against shard limits in some versions.**
View source on GitHub -
es.cluster_allocation_explain script low Low — read-only or trivially reversible
POST /_cluster/allocation/explain
Explain why an unassigned shard hasn't been placed. The canonical "why is my cluster yellow?" answer.
View source on GitHub -
es.cluster_health script low Low — read-only or trivially reversible
GET /_cluster/health
Show cluster status (green/yellow/red), node count, shard counts. Read-only.
View source on GitHub -
es.cluster_settings script low Low — read-only or trivially reversible
GET /_cluster/settings
Return persistent + transient cluster-level settings.
View source on GitHub -
es.flush script medium Medium — changes state, easily reversible
POST /<index>/_flush (flush index)
Flush the index — forces a Lucene commit so the translog is cleared, which speeds recovery if a shard later restarts. (Looking for synced flush? That API was removed in ES 8.0; a normal flush gives the same recovery benefit.)
View source on GitHub -
es.force_merge script high High — service-affecting
POST /<index>/_forcemerge
Merge segments down to `max_num_segments`. Expensive — heavy disk + CPU for the duration. Use on read-only indices (e.g., yesterday's logs) only.
View source on GitHub -
es.index_count script low Low — read-only or trivially reversible
GET /<index>/_count
Return the document count for one index.
View source on GitHub -
es.index_mapping script low Low — read-only or trivially reversible
GET /<index>/_mapping
Return the field mappings for one index.
View source on GitHub -
es.index_settings script low Low — read-only or trivially reversible
GET /<index>/_settings
Return one index's settings.
View source on GitHub -
es.index_stats script low Low — read-only or trivially reversible
GET /<index>/_stats
Show index-level stats — docs, store, indexing/search rates, fielddata.
View source on GitHub -
es.pending_tasks script low Low — read-only or trivially reversible
GET /_cluster/pending_tasks
List pending master tasks. A growing queue here means the master can't keep up.
View source on GitHub -
es.snapshot_list script low Low — read-only or trivially reversible
GET /_snapshot/<repo>/_all
List snapshots in one repository.
View source on GitHub -
es.snapshot_status script low Low — read-only or trivially reversible
GET /_snapshot/<repo>/<snap>/_status
Return the in-progress (or completed) status of one snapshot.
View source on GitHub