Query Context Engine AI Indices
<!-- begin-partial: preamble -->
Environment Configuration
This skill executes Elasticsearch operations through the
CLI. If the
CLI is not installed, tell the user what it is needed for. Do
not guess credentials, call the HTTP API directly, or attempt other workarounds.
This skill references operations in HTTP-shorthand form (e.g.,
,
,
,
GET /{index}/_settings/index.mode
,
). The
Operations table at the end of this document
maps each shorthand to the equivalent
CLI command — always use the CLI rather than calling the HTTP API
directly.
<!-- end-partial: preamble -->
Concepts
AI Index — an Elasticsearch index named
, or a data stream named
, registered with
the Context Engine under a logical id. The registration lives in Kibana; the knowledge lives in the backing index. Only
the list operation knows which
indices are registered and what to put in
; the index name alone does
not tell you.
Knowledge Indicator (KI) — one document in an AI Index: context prepared for agents, such as a description of some
data, a summary, an access pattern, a runnable query, or a record of a Kibana resource. A KI may answer a question
outright, or help you locate and use the source that does.
A KI is retired by a tombstone (
governance.lifecycle.status: deleted
) or by an
in the past. On a data
stream, one KI is several revisions under the same
, the newest of which is its current state. The query API returns
only current, active, unexpired KIs unless the query asks otherwise (see
Lifecycle).
Search the AI Indices before broader retrieval whenever their KIs may cover the question. This skill reads KIs;
generating them belongs to the Context Engine's automations and feedback loop.
Three read-only Context Engine HTTP APIs back this skill. The
Operations table maps each to its
CLI command:
| Operation | HTTP API (shorthand) | Input | Returns |
|---|
| List | GET kbn:/api/context_engine/ai_index
| — | { ai_indices: [{ id, description, managed, dest: { type, value } }] }
|
| Describe | GET kbn:/api/context_engine/ai_index/{aiIndexId}/_describe
| in the path | , a free-form context block (fields, counts, examples) |
| Query | POST kbn:/api/context_engine/ai_index/_query
| { query, params?, limit? }
| , ES|QL rows |
Use them in this order:
list → describe → query. Never guess an index id, a
target, or a field name; describe
supplies all three. Nothing else can read an AI Index correctly: a generic ES|QL query (
) or index listing
neither knows which indices are registered nor applies the space scoping.
Every call is scoped to one space, and the space comes from the request rather than from anything written into the
query. Point the request at another space to read that space's KIs.
The canonical KI schema
Elastic's canonical KI indices share these fields. Other AI Indices differ, so treat this as a starting shape and let
describe settle the fields for any given index.
| Field | ES|QL type | Purpose |
|---|
| keyword | Categorization, e.g. , , , |
| text | Short name of the KI or its backing entity |
| text | Short description of this KI |
| text | Full text: purpose, questions answered, access patterns |
| keyword | Filter facets; multi-valued, so use rather than |
| flattened | Structured keyword-queryable metadata (status, themes, entity names). holds runnable ES|QL |
| date | Optional; a KI whose has passed is expired and hidden by default |
governance.lifecycle.status
| keyword | marks a tombstone, hidden by default. On a data stream, only the newest revision's status counts |
governance.provenance.created_by.uri
| keyword | The automation that wrote the KI, as |
Semantic sub-fields use
dot notation:
,
,
. They exist only
where the mapping defines them; the describe block's
section lists the real ones.
— a KI's runnable ES|QL
When a KI carries runnable ES|QL, it lives in
. That is the canonical location; do not look elsewhere
in
. The field is optional, so a query must tolerate its absence. The same access pattern is also presented
as prose inside
— templates, params, and returns — so reach for
when a KI has no
,
or when the description of the query matters more than the query itself.
is
, so extract the value with
before filtering or keeping it:
esql
FROM <dest.value>
| WHERE governance.lifecycle.status IS NULL OR governance.lifecycle.status == "active"
| WHERE expires_at IS NULL OR expires_at > NOW()
| WHERE type == "detection"
| EVAL esql = FIELD_EXTRACT(attributes, "esql")
| WHERE esql IS NOT NULL
| KEEP title, description, esql
| LIMIT 5
A KI may store an array of queries, making the extracted value multivalued.
still filters correctly, but
scalar comparisons like
skip multivalued rows. Add
after the
to get one row per
query.
Flow
Step 1 — List the AI indices
Call
GET kbn:/api/context_engine/ai_index
. Each entry gives:
- , to pass to describe.
- , the exact string to put after . Use it verbatim: it differs from the id ( →
ai-index-idx-sales-knowledge
). says whether it is an or a .
- and , to choose between entries.
The list is scoped to the caller's space and to what the caller can read. An entry whose backing index is empty or does
not exist yet is still listed; an index the caller lacks
on is silently left out.
Skip this step when your instructions already name the index. Step 2 still applies: describe supplies the
target
and the field names either way.
Step 2 — Describe the one you picked
Call
GET kbn:/api/context_engine/ai_index/{aiIndexId}/_describe
with the
from Step 1. The
is a text
block meant to be
read, not parsed: no regexing it into structured data. It contains:
- the
Query with ES|QL against:
line (the target),
- , every mapped field as plus / (capped at 500; a path mapped
inconsistently across matched indices shows as ),
- , the searchable fields, when any,
- and , the top 20 KI / values by document count in this space, active and
unexpired only,
- , three ready ES|QL shapes, each opening with the lifecycle pipeline for the index's destination
type.
The block is capped at ~16k tokens. Read it and use it; do not echo it back to the user.
Step 3 — Query
Call
POST kbn:/api/context_engine/ai_index/_query
with
{ query, params?, limit? }
. Build the ES|QL from the describe
block's field list, starting from its example queries, and pass user input as named parameters (
,
,
) rather than interpolating it into the query string. The response is
; summarize it for the
user rather than dumping raw rows.
What the server owns and you cannot override:
| Constraint | Behavior |
|---|
| Lifecycle filter | Inserted after on any query that reads a registered AI Index: active and unexpired KIs only, newest revision per on a data stream, dropped when the query does not name it. See Lifecycle. |
| Space filter | Applied server-side from the request. Never write a space condition into the query: yours does not replace the server's and can silently match nothing. |
| Row limit | defaults to 100, max 1000. A smaller trailing in the query wins; a larger one is capped. |
| Query size | 10,000 characters max |
| At most 100 entries; keys ≤256 chars, string values ≤4096 chars |
| Index access | The query's decides what is read; Elasticsearch index privileges bound it. ES 4xx comes back as-is. |
There is no
and no
parameter. Express time windows in the ES|QL itself
(
WHERE @timestamp >= NOW() - 24 hours
) or through
.
Lifecycle
Open every query with the two lifecycle filters, unless reading retired KIs, and end row-returning queries in
(aggregations end in
): the query then reads as what it returns without pulling
into context.
esql
| WHERE governance.lifecycle.status IS NULL OR governance.lifecycle.status == "active"
| WHERE expires_at IS NULL OR expires_at > NOW()
The query API adds these two filters and
to any query that omits them, and on a data stream always
keeps only the newest revision per
(adding
when missing). A top-level
on a lifecycle
field switches off that field's filter only; showing the field in
does not. Any
column named
anywhere in the query, the opening status filter included, switches off the
, so a query that opens with the two
filters returns
columns unless it ends in
or
. An index that is not registered as an AI
Index is read as-is.
Examples
These run as-is against canonical KI indices. For any other AI Index, adapt the field names from the describe block:
does not exist unless the mapping has it.
Full-text search, lexical and semantic fused
esql
FROM ai-index-idx-sales-knowledge METADATA _id, _index, _score
| WHERE governance.lifecycle.status IS NULL OR governance.lifecycle.status == "active"
| WHERE expires_at IS NULL OR expires_at > NOW()
| FORK
( WHERE MATCH(title, ?query) OR MATCH(description, ?query) OR MATCH(content, ?query) | SORT _score DESC | LIMIT 20 )
( WHERE MATCH(title.semantic, ?query) OR MATCH(description.semantic, ?query) OR MATCH(content.semantic, ?query) | SORT _score DESC | LIMIT 20 )
| FUSE
| SORT _score DESC, _id ASC
| KEEP title, description, content, type, tags
| LIMIT 5
Called with the search phrase as a parameter:
json
{ "query": "<the esql above>", "params": { "query": "refund policy for annual plans" }, "limit": 5 }
Filter by KI type and tag
esql
FROM ai-index-idx-sales-knowledge
| WHERE governance.lifecycle.status IS NULL OR governance.lifecycle.status == "active"
| WHERE expires_at IS NULL OR expires_at > NOW()
| WHERE type == ?type AND MATCH(tags, ?tag)
| KEEP title, description, content, type, tags
| LIMIT 5
Count KIs by type
A first probe to confirm the index holds KIs visible from this space:
esql
FROM ai-index-idx-sales-knowledge
| WHERE governance.lifecycle.status IS NULL OR governance.lifecycle.status == "active"
| WHERE expires_at IS NULL OR expires_at > NOW()
| STATS count = COUNT(*) BY type
| SORT count DESC
| LIMIT 20
Read retired KIs, only when asked
Only when the user asks about deleted or expired knowledge. Tombstoned and expired KIs stay readable, on an index or a
data stream:
- Tombstoned: a on
governance.lifecycle.status
turns off the status filter and, being a
column, the too; the expiry filter still applies.
- Expired: a on turns off the expiry filter; the status filter still applies.
Nothing else is readable: a KI whose document was removed is gone, and older revisions on a data stream are never
returned.
esql
FROM ai-index-idx-sales-knowledge
| WHERE governance.lifecycle.status == "deleted"
| KEEP title, governance.provenance.created_by.uri
| LIMIT 20
On a data stream, the same query returns the KIs whose newest revision is a tombstone:
esql
FROM ai-index-ds-sales-knowledge
| WHERE governance.lifecycle.status == "deleted"
| KEEP title, governance.provenance.created_by.uri
| LIMIT 20
Diagnosing
These failure modes look alike from the outside and have different fixes. Work down the table.
| Symptom | Cause | Fix |
|---|
elastic kb context-engine
is not a known command | The installed CLI predates the Context Engine commands | Update the CLI |
| 404 from every Context Engine call in one space | is off in that space. Not a permissions problem | Turn it on in that space's advanced settings |
| 404 from every Context Engine call on every space | Kibana predates the Context Engine APIs | Check the version against the compatibility note above |
| 403 from every Context Engine call | Caller lacks the Context Engine Kibana privilege | Add Context Engine to the caller's role |
| 403 from query or describe only | Missing Elasticsearch index privilege on the backing indices | Grant (query) / and (describe) |
| Describe returns a block with no counts sections | / are not aggregatable fields, or no documents in this space | Expected; the rest of the block is still usable |
| An AI index you expect is not listed | No on its backing index, or every document in it belongs to another space | Check privileges and the space the request is scoped to |
| from a query whose id was listed | The AI Index is registered but its backing index does not exist yet | Expected for a registration with no data; pick another index |
| Error saying the query response is too large | The rows exceeded the 20 MB response cap | Narrow with (drop and other large fields), lower , or aggregate with |
| Query returns nothing but the index has data | Wrong space: the server-side space filter hides other spaces' documents | Scope the request to the right space |
| A KI you know exists is not returned | It is tombstoned, or its has passed | Filter on governance.lifecycle.status
or in a to read it (see Lifecycle) |
| No columns in the result | The query names no column, or a / leaves them out | Expected; name the field you need, e.g. in |
Guidelines
- Never skip describe. A query written from memory could fail, or silently returns nothing.
- Read AI Indices only through
POST kbn:/api/context_engine/ai_index/_query
. A direct Elasticsearch query or a
cluster-wide ES|QL query () bypasses the space scoping, the lifecycle filter, and the row cap: it
returns every revision, deleted and expired ones included. Consult the skill for ES|QL syntax.
- Start at 5 and narrow the columns with . The whole result enters your context.
- If the top 5 don't answer the question, check how they fall short: on topic but incomplete → raise the limit; off
topic → the query is wrong, so reword the search terms or loosen the rather than asking for more rows.
- Answer from the rows and cite the KI titles; do not dump the raw result.
- An empty result means no current KI. Do not read tombstones or expired KIs unless the user asks about deleted or
expired knowledge.
Out of scope
- Creating, updating, or deleting AI indices, and managing their / / config.
- Generating Knowledge Indicators, or deciding what an AI Index should contain. That is the Context Engine's automations
and its analyze-and-improve feedback loop, not query time.
Operations
| HTTP API (shorthand) | CLI command |
|---|
GET kbn:/api/context_engine/ai_index
| elastic kb context-engine get-context-engine-ai-index
|
GET kbn:/api/context_engine/ai_index/{aiIndexId}/_describe
| elastic kb context-engine get-context-engine-ai-index-aiindexid-describe --ai-index-id '<id>'
|
POST kbn:/api/context_engine/ai_index/_query
| elastic kb context-engine post-context-engine-ai-index-query --query '<esql>' [--params '<json>'] [--limit <n>]
|
GET kbn:/api/context_engine/ai_index/{aiIndexId}
| elastic kb context-engine get-context-engine-ai-index-aiindexid --ai-index-id '<id>'
|