@carllee1983/dbcli 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ All notable changes to dbcli are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.8.0] - 2026-05-06
9
+
10
+ ### Added
11
+
12
+ - **Redis 與 Elasticsearch 支援**:`init`、`list`、`schema`、`query`、`status`、`use`、`doctor`、`upgrade`、`completion` 在兩個系統皆真實可用。
13
+ - Redis:`list` 透過 SCAN 取 keys;`schema <key>` 顯示 type/TTL/size/sample;`query` 執行白名單 Redis 指令並走原本權限與黑名單檢查。
14
+ - Elasticsearch:`list` 顯示 indices 與文件數;`schema [index]` 攤平 mapping、揭露 `.fields` multi-fields;`query` 接受 DSL JSON 或 Lucene 字串。
15
+ - 文件:`assets/SKILL.md` 與 `assets/reference.md` 同步加入 Redis / Elasticsearch 章節。
16
+
17
+ ### Fixed
18
+
19
+ - **`insert` / `update` / `delete` / `export` / `diff` 對 Redis / Elasticsearch 的早期錯誤訊息**:先前會落入 SQL DataExecutor 出現「Column ... not found in table」之類誤導訊息,現在直接回傳明確的「不支援」JSON,並指引正確替代路徑(Redis 改用 `query`、Elasticsearch 改用外部工具或 `query --index`)。
20
+ - **TypeScript 嚴格度**:`bun run typecheck` 從 43 個錯誤降為 0。
21
+ - `ConnectionConfig` union 加入 `ElasticsearchConnectionConfig`。
22
+ - `ResolvedConnection.connection.system`、`ReplContext.system` 涵蓋 `'elasticsearch'`。
23
+ - `ExecutionResult` 補上 optional `rowCount` / `columnNames`。
24
+ - `getDefaultsForSystem` 涵蓋 redis (6379) / elasticsearch (9200) 預設值。
25
+
8
26
  ## [1.7.0] - 2026-05-04
9
27
 
10
28
  ### Added
package/assets/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: dbcli
3
- description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete, export results, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, and MongoDB with multiple named connections per project and custom env files. Trigger when working with databases, running SQL or MongoDB JSON queries, exploring table/collection structures, switching database environments, or protecting sensitive data from AI access. For exhaustive flags and examples, read the sibling `reference.md`.
3
+ description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete, export results, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch with multiple named connections per project and custom env files. Trigger when working with databases, running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL, exploring table/collection/key/index structures, switching database environments, or protecting sensitive data from AI access. For exhaustive flags and examples, read the sibling `reference.md`.
4
4
  ---
5
5
 
6
6
  # dbcli
@@ -33,21 +33,21 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
33
33
  |---------|-----------------|---------|
34
34
  | `init` | n/a | Create `.dbcli` (v1 single or v2 multi via `--conn-name` / `--env-file`). **Usually run by the human** — do NOT re-run to strip `{"$env"}` references; that format is intentional. |
35
35
  | `use` | n/a | Show/switch default named connection (v2 only). |
36
- | `list` | query-only+ | Tables (SQL) or collections (MongoDB). |
37
- | `schema` | query-only+ | Per-table or full scan into `.dbcli/schemas/`; use `--use` for the correct connection cache. |
38
- | `query` | query-only+ | SQL, or Mongo JSON filter / pipeline with `--collection`. |
39
- | `insert` / `update` | read-write+ | JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. |
40
- | `delete` | data-admin+ | `--where` required; `--dry-run` first. |
41
- | `export` | query-only+ | Query → CSV/JSON file or stdout. |
36
+ | `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
37
+ | `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/` (use `--use` for the right cache). MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). |
38
+ | `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`/`--index`). |
39
+ | `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. |
40
+ | `delete` | data-admin+ | SQL or MongoDB only. `--where` required; `--dry-run` first. |
41
+ | `export` | query-only+ | SQL or MongoDB only. Query → CSV/JSON(L) file or stdout. |
42
42
  | `blacklist` | n/a | `list` / `table` / `column` subcommands redact sensitive data from query results. |
43
- | `check` | query-only+ | Table health: nulls, duplicates, orphans, rowCount, size. |
44
- | `diff` | query-only+ | Save/compare schema snapshots. |
43
+ | `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
44
+ | `diff` | query-only+ | SQL only. Save/compare schema snapshots. |
45
45
  | `status` | query-only+ | Safe JSON/text summary (no credentials). |
46
- | `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age. |
46
+ | `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age; ES has a dedicated path. |
47
47
  | `completion` | n/a | bash / zsh / fish scripts. |
48
48
  | `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
49
- | `shell` | (same as query+) | Interactive REPL. |
50
- | `migrate` | admin | **DDL; dry-run by default** — needs `--execute`; DROP also needs `--force`. |
49
+ | `shell` | (same as query+) | Interactive REPL. SQL engines + MongoDB shell only; Redis/ES not currently exposed in REPL. |
50
+ | `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`; DROP also needs `--force`. Mongo/Redis exit with error. |
51
51
 
52
52
  `--use <name>` on any subcommand targets a v2 connection without changing the default.
53
53
 
@@ -69,11 +69,33 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
69
69
  ## MongoDB
70
70
 
71
71
  - JSON filter object (`find`) or JSON array (`aggregate`); SQL is rejected. `--collection <name>` is required on `query`.
72
- - **Supported:** `init`, `list`, `query`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`.
73
- - **Not supported:** `schema`, `insert`, `update`, `delete`, `export`, `diff`, `migrate`, `check`.
74
- - No auto-limit on MongoDB queries use `$limit` in the pipeline if needed.
72
+ - **Supported:** `init`, `list`, `schema` (sampled), `query`, `insert`, `update`, `delete`, `export`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`.
73
+ - **Not supported:** `q` (saved queries), `diff`, `migrate`, `check`.
74
+ - Schema is **sampled** (default 50 docs, `--sample-size`); types are JS `typeof` strings no PK/FK/index info.
75
+ - `--limit` applies on `find`/aggregate; query-only mode caps at 1000 unless `--no-limit`.
75
76
  - See reference.md MongoDB section for full syntax and examples.
76
77
 
78
+ ## Redis
79
+
80
+ - Command-style execution; `query` runs a whitelisted Redis command (e.g. `GET`, `HSET`, `DEL`).
81
+ - **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
82
+ - **Not supported:** `schema` full scan / `--refresh` / `--reset`, `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`.
83
+ Use `query "DEL <key>"` etc. for writes — they go through the same permission gate.
84
+ - Permission tiers map to commands: read commands → `query-only`; mutators (`SET`, `HSET`, `EXPIRE`, …) → `read-write`; `DEL` / `HDEL` / `UNLINK` → `data-admin`; `KEYS`, `FLUSHDB`, `CONFIG`, `INFO`, … → `admin`. Unlisted commands are denied.
85
+ - `database` field is the logical DB index (default `0`); `list` returns ≤ 100 000 keys via SCAN.
86
+ - See reference.md Redis section.
87
+
88
+ ## Elasticsearch
89
+
90
+ - DSL (JSON body) or Lucene query string; `--collection <index>` (or `--index <index>`) is required on `query`.
91
+ - **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
92
+ - **Not supported:** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`.
93
+ Writes are not exposed via dedicated subcommands yet — use external tooling for indexing.
94
+ - Auth: API key (`apiKey`), Basic (`user`/`password`), or Cloud ID (`cloudId`); supports HTTPS, custom CA (`caPath`), and multi-node arrays (`nodes`).
95
+ - Query-only mode caps at 1000 hits; `--no-limit` is bounded at 10 000 (use saved searches with `search_after` beyond that).
96
+ - Schema flattens nested fields (`a.b.c`) and surfaces `.fields` multi-fields (e.g. `text.keyword`).
97
+ - See reference.md Elasticsearch section.
98
+
77
99
  ## Saved queries
78
100
 
79
101
  Run reusable parameterised SELECT snippets stored in your repo.
@@ -21,6 +21,14 @@ dbcli init --system mongodb --uri "mongodb://user:pass@host:27017/mydb?authSourc
21
21
  dbcli init --system mongodb --host localhost --port 27017 --user admin --password secret --name mydb
22
22
  dbcli init --system mongodb --host localhost --port 27017 --name mydb # No auth
23
23
 
24
+ # Redis (database = logical DB index)
25
+ dbcli init --system redis --host localhost --port 6379
26
+ dbcli init --system redis --host localhost --port 6379 --password secret --name 0
27
+
28
+ # Elasticsearch
29
+ dbcli init --system elasticsearch --host localhost --port 9200 --user elastic --password changeme
30
+ dbcli init --system elasticsearch --cloud-id "myCluster:dXMtZWFzdC0xLmF3..." --api-key "<base64>"
31
+
24
32
  # Multi-connection (v2 format)
25
33
  dbcli init --conn-name staging --env-file .env.staging # Named connection with custom env file
26
34
  dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-test
@@ -32,6 +40,10 @@ dbcli init --rename staging:production # Rename a connection
32
40
 
33
41
  **MongoDB-specific options:** `--uri <uri>` (full connection URI), `--auth-source <db>` (auth database, default: `admin` when user/password set)
34
42
 
43
+ **Elasticsearch-specific options:** `--cloud-id <id>` (Elastic Cloud), `--api-key <key>` (ApiKey auth). Other ES fields (`nodes[]`, `protocol`, `caPath`, `rejectUnauthorized`) can be edited directly in `.dbcli`.
44
+
45
+ **Redis note:** the `database` (or `--name`) field is the logical DB index (`"0"` … `"15"`), not a database name.
46
+
35
47
  **Multi-connection:** Using `--conn-name` or `--env-file` creates a v2 config with named connections. Each connection can have its own env file and permission level. Existing v1 configs are automatically imported as the `default` connection when upgrading.
36
48
 
37
49
  > **AI agent note on `--use-env-refs`:** If an existing `.dbcli` config contains `{"$env": "DB_HOST"}` style references, the connection values are read from environment variables at runtime. Do NOT re-run `init` to replace these references with actual values — the env-ref format is intentional for CI/CD and multi-environment setups.
@@ -57,16 +69,19 @@ dbcli list --use prod
57
69
 
58
70
  ### list
59
71
 
60
- List all tables (SQL) or collections (MongoDB).
72
+ List all tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch).
61
73
 
62
74
  ```bash
63
75
  dbcli list
64
76
  dbcli list --format json
77
+ dbcli list --include-system # Elasticsearch: include `.system` indices
65
78
  ```
66
79
 
67
80
  **Permission:** query-only+
68
81
 
69
- > **MongoDB:** Lists collections with estimated document count instead of tables.
82
+ > **MongoDB:** Lists collections with estimated document count.
83
+ > **Redis:** Returns up to 100 000 keys via `SCAN MATCH * COUNT 1000`. The header reads `Keys in db <n> (redis):` where `<n>` is the logical DB index.
84
+ > **Elasticsearch:** Returns indices with `documentCount` from `/_stats/docs`; aliases are tagged separately. System indices (names starting with `.`) are hidden unless `--include-system` is passed.
70
85
 
71
86
  ### schema
72
87
 
@@ -90,6 +105,9 @@ dbcli schema --use prod # Scan prod DB; saves to .dbcli/schemas/prod
90
105
 
91
106
  **Schema storage (v1.4+):** Schema is persisted as layered files under `.dbcli/schemas/`. With v2 multi-connection config each connection gets its own subdirectory (`.dbcli/schemas/<connection>/`). Run `dbcli schema --use <connection>` once per connection before querying it — otherwise `schema <table>` may return data from the wrong connection's cache.
92
107
 
108
+ > **Redis:** `schema <key>` is required (no full scan). The output exposes `type`, `ttl`, `size`, and a small `sample` (e.g. first 5 hash keys). `--reset` / `--refresh` are rejected — Redis caches no schema.
109
+ > **Elasticsearch:** `schema [index]` flattens the `_mapping` properties (nested `a.b.c`) and emits each `.fields` multi-field as a separate column (e.g. `text` + `text.keyword`). Full scan iterates all non-system indices and stores per-connection caches alongside SQL engines.
110
+
93
111
  ### query
94
112
 
95
113
  Execute SQL query (MySQL/PostgreSQL/MariaDB) or JSON filter/pipeline (MongoDB).
@@ -106,16 +124,38 @@ dbcli query '{"age": {"$gt": 18}}' --collection users --format json
106
124
 
107
125
  # MongoDB: aggregation pipeline
108
126
  dbcli query '[{"$match": {"status": "active"}}, {"$group": {"_id": "$role", "count": {"$sum": 1}}}]' --collection users
127
+
128
+ # Redis: any whitelisted command (permission-gated by command)
129
+ dbcli query "GET session:abc"
130
+ dbcli query "HGETALL user:42" --format json
131
+ dbcli query "SCAN 0 MATCH user:* COUNT 100"
132
+ dbcli query "SET feature:flag enabled" # requires read-write+
133
+ dbcli query "DEL stale:key" # requires data-admin+
134
+
135
+ # Elasticsearch: DSL body or Lucene q-string
136
+ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
137
+ dbcli query 'status:active AND amount:>100' --index orders --limit 50
109
138
  ```
110
139
 
111
- **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB only)
112
- **Permission:** query-only+
140
+ **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`)
141
+ **Permission:** query-only+ (Redis: per-command; Elasticsearch: per HTTP method/path)
113
142
 
114
143
  > **MongoDB notes:**
115
144
  > - SQL syntax is rejected — use JSON object (filter) or JSON array (pipeline)
116
145
  > - `--collection <name>` is required
117
146
  > - Auto-limit does not apply; use `$limit` in your pipeline if needed
118
147
 
148
+ > **Redis notes:**
149
+ > - The first token must be an allow-listed command (`GET`/`SET`/`HGET`/`HSET`/`DEL`/...). Unknown commands are refused.
150
+ > - Permission tier is derived from the command (read → `query-only`, write → `read-write`, delete → `data-admin`, `KEYS`/`FLUSHDB`/`CONFIG`/... → `admin`).
151
+ > - Output is always shaped into rows: scalar replies become `{value: ...}`; arrays become indexed rows; `HGETALL` is folded into a single object.
152
+
153
+ > **Elasticsearch notes:**
154
+ > - `--collection` (or `--index`) is required.
155
+ > - A body that begins with `{` is sent as DSL via `POST /<index>/_search`; otherwise the value is URL-encoded into `?q=...` (Lucene query string) via `GET`.
156
+ > - Hits are flattened: each result row contains `_id` plus dotted-path fields from `_source`. Pass `--format json` to keep nested structures readable.
157
+ > - Query-only mode caps at 1000 hits; `--no-limit` is internally capped at 10 000 (use saved searches / `search_after` for deeper pagination).
158
+
119
159
  ### q
120
160
 
121
161
  Run a saved query snippet by `@name`. Snippets are parameterised SELECT/WITH statements resolved from three layers, with **local > shared > builtin** precedence (a local file always shadows shared and builtin variants of the same key):
@@ -508,3 +548,144 @@ dbcli delete orders --where '{"status":"cancelled"}' --force
508
548
  | Field filter | `'{"field": "value"}'` |
509
549
  | Comparison | `'{"age": {"$gt": 18}}'` |
510
550
  | Aggregation | `'[{"$match": {...}}, {"$group": {...}}]'` |
551
+
552
+ ## Redis Support
553
+
554
+ Redis connections speak Redis commands rather than SQL. The adapter uses the `ioredis` driver and exposes a narrow, permission-gated surface.
555
+
556
+ **Supported commands:** `init`, `use`, `list`, `schema`, `query`, `status`, `doctor`, `upgrade`, `completion`
557
+
558
+ **Not supported (exit with error or unsupported error):** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q` (saved queries), `shell`. For writes, run the equivalent Redis command via `query` — the same permission gate applies.
559
+
560
+ ### Connection and configuration
561
+
562
+ - Required fields: `system: redis`, `host`, `port`. `password` and `database` are optional.
563
+ - `database` is the **logical DB index** (`"0"` … `"15"`), kept as a string to play nicely with env-ref bindings. `list` and the connection metadata both label it as the active DB.
564
+ - `connection.timeout` (ms, default 5000) maps to ioredis's `connectTimeout`.
565
+
566
+ ### Permission classification
567
+
568
+ Permission is derived from the command's first token (case-insensitive). Unknown commands are denied even at `admin` tier — they must be added to the allow-list.
569
+
570
+ | Tier | Commands |
571
+ |------|----------|
572
+ | `query-only` | `GET`, `MGET`, `STRLEN`, `EXISTS`, `TTL`, `PTTL`, `TYPE`, `SCAN`, `HGET`, `HGETALL`, `HKEYS`, `HVALS`, `HLEN`, `HEXISTS`, `HMGET`, `LRANGE`, `LLEN`, `LINDEX`, `SMEMBERS`, `SCARD`, `SISMEMBER`, `ZRANGE`, `ZREVRANGE`, `ZRANGEBYSCORE`, `ZCARD`, `ZSCORE`, `PING`, `ECHO` |
573
+ | `read-write` | `SET`, `SETEX`, `SETNX`, `PSETEX`, `MSET`, `MSETNX`, `APPEND`, `INCR`/`INCRBY`, `DECR`/`DECRBY`, `HSET`/`HSETNX`/`HMSET`/`HINCRBY`, `LPUSH`/`RPUSH`/`LPOP`/`RPOP`/`LSET`, `SADD`/`SREM`, `ZADD`/`ZREM`, `EXPIRE`/`EXPIREAT`/`PEXPIRE`/`PERSIST`, `RENAME` |
574
+ | `data-admin` | `DEL`, `UNLINK`, `HDEL` |
575
+ | `admin` | `FLUSHDB`, `FLUSHALL`, `CONFIG`, `INFO`, `CLIENT`, `DEBUG`, `SHUTDOWN`, `KEYS`, `MONITOR`, `SAVE`, `BGSAVE`, `BGREWRITEAOF`, `REPLICAOF`, `SLAVEOF`, `ACL` |
576
+
577
+ ### Schema inspection
578
+
579
+ `schema <key>` returns one synthetic row per key with these columns:
580
+
581
+ | column | meaning |
582
+ |--------|---------|
583
+ | `type` | Redis type (`string` / `hash` / `list` / `set` / `zset` / `stream` / `none`) |
584
+ | `ttl` | `<n>s`, `no expiry`, or `missing` |
585
+ | `size` | `STRLEN` / `HLEN` / `LLEN` / `SCARD` / `ZCARD` / `XLEN` depending on type |
586
+ | `sample` | First 5 hash field names (hash only) |
587
+
588
+ `schema` (no key) and `--refresh` / `--reset` are rejected — there is no full-database schema cache for Redis.
589
+
590
+ ### Recommended `query` patterns
591
+
592
+ ```bash
593
+ # Read
594
+ dbcli query "GET feature:flag"
595
+ dbcli query "HGETALL user:42" --format json
596
+ dbcli query "LRANGE queue:jobs 0 9"
597
+
598
+ # Iterate keys (paginated; never use KEYS — admin-only)
599
+ dbcli query "SCAN 0 MATCH session:* COUNT 200"
600
+
601
+ # Write (requires read-write+)
602
+ dbcli query "SET counter 1"
603
+ dbcli query "EXPIRE session:abc 3600"
604
+ dbcli query "HSET user:42 name Alice"
605
+
606
+ # Delete (requires data-admin+)
607
+ dbcli query "DEL temp:lock"
608
+ dbcli query "HDEL user:42 lastLogin"
609
+ ```
610
+
611
+ ### Limitations
612
+
613
+ - No `--dry-run` for writes — Redis commands execute immediately. Pair writes with a confirming read (`GET`, `HGETALL`, `EXISTS`).
614
+ - No transaction wrapping (`MULTI`/`EXEC`). Submit one command at a time.
615
+ - `KEYS` requires `admin`. Prefer `SCAN` for routine work.
616
+ - Blacklist rules are not enforced for Redis (there is no concept of "column" / "table" the validator can map). Be careful with sensitive key prefixes.
617
+
618
+ ## Elasticsearch Support
619
+
620
+ Elasticsearch connections speak the REST API. The adapter is fetch-based (no SDK) and supports HTTPS, custom CA, API key, basic auth, and Cloud ID.
621
+
622
+ **Supported commands:** `init`, `use`, `list`, `schema`, `query`, `status`, `doctor`, `upgrade`, `completion`
623
+
624
+ **Not supported (use external tooling):** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`, `shell`. The permission classifier already understands `_doc` / `_update` / `_bulk` so future write surfaces can be wired in without changing tiers.
625
+
626
+ ### Connection and configuration
627
+
628
+ - Either `host` + `port` (default `https://localhost:9200`) or `nodes: [...]` (first node is used) or `cloudId`.
629
+ - Auth precedence: `apiKey` → `user`/`password` (HTTP Basic). Leave both unset for an open cluster.
630
+ - `protocol` defaults to `https`. For TLS quirks: `caPath` (path to a PEM bundle) and `rejectUnauthorized: false` (last resort).
631
+ - `connection.timeout` (ms, default 5000) is wired to `AbortController` on every request.
632
+
633
+ ### Permission classification
634
+
635
+ Each REST request is mapped to a SQL-shaped tier based on method + path:
636
+
637
+ | ES surface | Mapped to | Permission |
638
+ |------------|-----------|------------|
639
+ | `GET _search` / `_count` / `_mapping` / `_settings` / `_alias` / `GET _doc` / `_source` | `SELECT` | `query-only` |
640
+ | `POST _update` / `POST _doc` | `UPDATE` | `read-write` |
641
+ | `PUT _doc` / `_create` | `INSERT` | `read-write` |
642
+ | `DELETE` (any) | `DELETE` | `data-admin` |
643
+ | `_bulk` | highest tier among the NDJSON actions (`delete` ⇒ `data-admin`) | derived |
644
+ | Anything else | `DROP` | `admin` (deny by default) |
645
+
646
+ ### Schema inspection
647
+
648
+ `schema [index]` calls `GET /<index>/_mapping` and flattens nested properties into dotted-path columns. Multi-fields under `.fields` (e.g. `text` → `text.keyword`) are emitted as separate columns. All fields are reported as nullable. There is no PK / FK / index info.
649
+
650
+ `schema` (no argument) iterates all non-system indices through the standard full-scan code path and writes per-connection caches under `.dbcli/schemas/<connection>/`.
651
+
652
+ ### Query semantics
653
+
654
+ - `--collection <index>` (or `--index <index>`) is required.
655
+ - Body that starts with `{` → sent as JSON DSL via `POST /<index>/_search`. Body otherwise → URL-encoded into `?q=...` (Lucene query string) on `GET`.
656
+ - Hits are flattened: each row carries `_id` plus dotted-path fields lifted from `_source`. Use `--format json` to inspect raw nested structure.
657
+ - Query-only mode caps `size` at 1000. `--no-limit` is internally capped at 10 000; for deeper pagination use the API directly with `search_after` or PIT.
658
+
659
+ ### Recommended `query` patterns
660
+
661
+ ```bash
662
+ # DSL match
663
+ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders --format json
664
+
665
+ # DSL with sort + size
666
+ dbcli query '{"query":{"range":{"created_at":{"gte":"2026-01-01"}}},"sort":[{"created_at":"desc"}],"size":50}' \
667
+ --collection orders
668
+
669
+ # Aggregation
670
+ dbcli query '{"size":0,"aggs":{"by_status":{"terms":{"field":"status.keyword"}}}}' \
671
+ --collection orders --format json
672
+
673
+ # Lucene query string
674
+ dbcli query 'status:active AND amount:>100' --index orders --limit 100
675
+ ```
676
+
677
+ ### Doctor and diagnostics
678
+
679
+ `dbcli doctor` runs a dedicated Elasticsearch path:
680
+
681
+ - Verifies REST connectivity to `GET /`.
682
+ - Reads `version.number` and runs the standard version freshness check.
683
+ - Walks every index via `listTables()` + `getTableSchema()` to feed the blacklist completeness check and the large-table heuristic (using `documentCount`).
684
+ - Standard schema-cache freshness using `schemaLastUpdated`.
685
+
686
+ ### Limitations
687
+
688
+ - Writes (`insert`/`update`/`delete`/`export`) are not exposed yet — the adapter implements them, but the CLI currently only routes them for SQL and MongoDB.
689
+ - No `_search/scroll` or PIT pagination at the CLI layer; large pulls need a saved external script.
690
+ - `check`, `diff`, `migrate`, and `q` are SQL-only and exit with errors (or fall through to a generic "unsupported" path).
691
+ - Blacklist column rules are applied to flattened hit rows on `query`; table-level blacklist rejects an index up front.