How elastichq/elasticsearch-hq works
1. ElasticHQ is a two-tier application: a Python backend serves the API and HTML shell, and a JavaScript single-page UI provides the operator console. The system’s purpose is to monitor and administer one or more Elasticsearch clusters.
2. The primary external dependency is Elasticsearch itself. The backend talks to remote clusters for cluster state, node stats, indices, snapshots, queries, and diagnostics; the UI never talks directly to Elasticsearch and instead uses ElasticHQ’s HTTP API.
3. The backend entrypoints are application.py and manage.py, with production process configs in deployment/ for Gunicorn, logging, and Supervisor. This suggests a Flask-style web server packaging that can run standalone, behind a process manager, or inside Docker/OpenShift.
4. Backend routing is organized under elastichq/api/. These modules split the HTTP surface by domain: clusters, nodes, indices, snapshots, diagnostics, query, status, REST passthrough, and a socket endpoint. endpoints.py and hq.py look like shared routing/landing-page concerns.
5. The backend service layer in elastichq/service/ is the core orchestration boundary. It contains per-domain services such as ClusterService, NodeService, IndicesService, SnapshotService, QueryService, DiagnosticsService, HQService, plus ConnectionService for Elasticsearch connectivity. This layer likely transforms ES responses into UI-friendly payloads and centralizes business rules.
6. Persistence is separate from live cluster access. elastichq/service/persistence/ClusterDBService.py and the migrations/ directory indicate a small local database for saved cluster definitions/settings, with Alembic-managed schema changes. Live cluster metrics remain ephemeral and are fetched from Elasticsearch on demand.
7. Background or asynchronous work is modeled explicitly in elastichq/common/JobPool.py, TaskPool.py, and model/Task.py. That implies some operations are queued or tracked over time, likely for longer-running actions such as diagnostics, indexing operations, or cluster tasks that the UI polls through the API.
8. The frontend lives under ui/ and is built separately from the Python backend. It is a component/container-based AngularJS-era app with services, filters, factories, and many feature modules. Webpack configs at the repo root bundle assets into elastichq/static/, which the backend serves.
9. UI architecture is feature-oriented around clusters and Elasticsearch objects. Containers and components cover cluster overview, nodes, indices, aliases, snapshots, diagnostics, query, REST API browsing, and settings. The UI uses dedicated services such as cluster-connection, cluster-indices, cluster-nodes, and hq to call the backend API.
10. Real-time and dashboard-style views are a major presentation boundary. Components such as line graphs, summary cards, node tables, and index metric panels consume backend data and render operational status for cluster health, docs, search load, JVM, filesystem, process, and shard state.
11. The templates/ and static/ directories on the Python side show that the backend also serves the SPA shell and compiled assets. elastichq/templates/index.html is the host page, while bundled CSS/JS in elastichq/static/ are the deployable frontend artifacts.
12. Testing is split along the same architectural lines. tests/es_versions/ exercises Elasticsearch-version-specific backend behavior, tests/combined/ covers integrated flows, and the various Docker Compose files under tests/ spin up versioned Elasticsearch environments. This is important because compatibility across ES 2.x through 7.x is a first-class architectural constraint.
13. Deployment is container-friendly and environment-driven. The repository includes a root Dockerfile, example Compose setups, and OpenShift manifests/proxy config, which implies the app is commonly deployed as a single web container that connects outward to user-provided Elasticsearch clusters rather than co-locating with Elasticsearch.
14. Documentation is generated with Sphinx and versioned under docs/, but it is not part of runtime behavior. The doc tree mirrors the backend module structure, which reinforces the separation between API layer, service layer, model layer, and frontend UI.
15. In diagram form, the key flow is: browser UI → ElasticHQ HTTP endpoints → service layer → Elasticsearch clusters, with a side path to local persistence for saved cluster metadata and a separate path for task/background bookkeeping. The backend is the central control plane; Elasticsearch is the data source and execution target.
Main entry points: service Service layer · api API layer · containers Feature views · services UI services
Components 34
Python backend
Flask-style HTTP API, service orchestration, persistence, and process entrypoints.
- application.py · WSGI/HTTP server entrypoint for the web app.
application.py - manage.py · Administrative command entrypoint.
manage.py - API layer · Domain HTTP endpoints and shared routing concerns.
elastichq/api - Clusters API · Cluster-level HTTP operations and status.
elastichq/api/clusters.py - Nodes API · Node statistics and node-facing operations.
elastichq/api/nodes.py - Indices API · Index administration and metrics endpoints.
elastichq/api/indices.py - Snapshots API · Snapshot and repository operations.
elastichq/api/snapshot.py - Query API · Search/query execution surface.
elastichq/api/query.py - Diagnostics API · Cluster health checks and diagnostics surface.
elastichq/api/diagnostics.py - REST passthrough · Generic Elasticsearch REST proxy surface.
elastichq/api/rest.py - Socket API · Socket-based endpoint for live updates or tasks.
elastichq/api/socket.py - HQ routes · Landing-page and shared HQ routing concerns.
elastichq/api/hq.py - Service layer · Core business logic and Elasticsearch-facing orchestration.
elastichq/service - Connection · Connection management to remote Elasticsearch clusters.
elastichq/service/ConnectionService.py - Cluster service · Cluster state and cluster-level aggregation logic.
elastichq/service/ClusterService.py - Node service · Node stats and node detail assembly.
elastichq/service/NodeService.py - Indices service · Index metadata, metrics, and admin operations.
elastichq/service/IndicesService.py - Snapshot service · Snapshot and repository workflows.
elastichq/service/SnapshotService.py - Query service · Search execution and result shaping.
elastichq/service/QueryService.py - Diagnostics service · Diagnostics execution and rule evaluation.
elastichq/service/DiagnosticsService.py - HQ service · Shared application-level coordination for the shell and API.
elastichq/service/HQService.py - Persistence · Small local database for saved cluster metadata and settings.
elastichq/service/persistence - Cluster DB · Local cluster-definition persistence service.
elastichq/service/persistence/ClusterDBService.py - Task model · Tracked asynchronous task or job state.
elastichq/model/Task.py - Task pools · Job and task pooling for background or long-running work.
elastichq/common/TaskPool.py - Job pool · Queued task execution and polling support.
elastichq/common/JobPool.py
Web UI
AngularJS-style single-page operator console and its bundle pipeline.
- UI shell · Standalone single-page operator console served as compiled assets.
ui - App module · Frontend application bootstrap and module wiring.
ui/src/app.module.js - UI services · Frontend services that call ElasticHQ HTTP endpoints.
ui/src/services - Cluster client · Cluster-related backend API client.
ui/src/services/cluster-connection/cluster-connection.service.js - Indices client · Index-related backend API client.
ui/src/services/cluster-indices/cluster-indices.service.js - Nodes client · Node-related backend API client.
ui/src/services/cluster-nodes/cluster-nodes.service.js - HQ client · Shared frontend API client for app-level operations.
ui/src/services/hq/hq.service.js - Feature views · Page-level containers for cluster administration workflows.
ui/src/containers
Connections 45
- application.py → API layer: serves routes · The backend entrypoint exposes the API surface.
- application.py → UI shell: serves assets · The backend serves the compiled SPA shell and static bundle.
- manage.py → Service layer: drives config · Administrative commands initialize and manage backend components.
- API layer → Clusters API: includes · Cluster HTTP surface is split into domain routes.
- API layer → Nodes API: includes · Node HTTP surface is split into domain routes.
- API layer → Indices API: includes · Index HTTP surface is split into domain routes.
- API layer → Snapshots API: includes · Snapshot HTTP surface is split into domain routes.
- API layer → Query API: includes · Query HTTP surface is split into domain routes.
- API layer → Diagnostics API: includes · Diagnostics HTTP surface is split into domain routes.
- API layer → REST passthrough: includes · Generic Elasticsearch passthrough routing.
- API layer → Socket API: includes · Realtime socket endpoint is part of the API layer.
- API layer → HQ routes: includes · Shared landing-page and HQ routing lives here.
- Clusters API → Service layer: uses · Cluster endpoints delegate to service orchestration.
- Nodes API → Service layer: uses · Node endpoints delegate to service orchestration.
- Indices API → Service layer: uses · Index endpoints delegate to service orchestration.
- Snapshots API → Service layer: uses · Snapshot endpoints delegate to service orchestration.
- Query API → Service layer: uses · Query endpoints delegate to service orchestration.
- Diagnostics API → Service layer: uses · Diagnostics endpoints delegate to service orchestration.
- REST passthrough → Connection: proxied via · REST passthrough goes through the Elasticsearch connection layer.
- Service layer → Connection: connects to · Shared connection handling underpins all cluster operations.
- Service layer → Cluster service: contains · Cluster orchestration is a primary service boundary.
- Service layer → Node service: contains · Node orchestration is a primary service boundary.
- Service layer → Indices service: contains · Index orchestration is a primary service boundary.
- Service layer → Snapshot service: contains · Snapshot orchestration is a primary service boundary.
- Service layer → Query service: contains · Query orchestration is a primary service boundary.
- Service layer → Diagnostics service: contains · Diagnostics orchestration is a primary service boundary.
- Service layer → HQ service: contains · Shared HQ coordination lives in the service layer.
- Cluster service → Cluster DB: persists · Cluster definitions and settings are stored locally.
- Cluster DB → Persistence: part of · Local persistence is grouped as a dedicated backend boundary.
- Diagnostics service → Task pools: queues · Long-running diagnostics or similar work can be queued.
- Task pools → Job pool: coordinates · Task and job pooling coordinate asynchronous execution.
- Task pools → Task model: tracks · Task records describe queued or running work.
- UI shell → App module: bootstraps · The frontend app module initializes the SPA.
- UI shell → UI services: contains · Frontend service layer groups HTTP clients.
- UI shell → Feature views: contains · Page-level views are organized as containers.
- UI services → Cluster client: includes · Cluster client is one of the core UI API services.
- UI services → Indices client: includes · Indices client is one of the core UI API services.
- UI services → Nodes client: includes · Nodes client is one of the core UI API services.
- UI services → HQ client: includes · Shared HQ client supports app-level UI flows.
- Feature views → Cluster client: calls · Feature views use dedicated backend API clients.
- Feature views → Indices client: calls · Feature views use dedicated backend API clients.
- Feature views → Nodes client: calls · Feature views use dedicated backend API clients.
- Feature views → HQ client: calls · Feature views use shared backend API clients.
- Feature views → API layer: via HTTP · The browser talks only to ElasticHQ API endpoints, not Elasticsearch directly.
- Connection → Clusters API: fetches state · Service layer retrieves cluster data from remote Elasticsearch clusters.