Query AI Indices
Base URL
https://{kibana_url}
POST
/api/context_engine/ai_index/_query
POST
/s/{space_id} /api/context_engine/ai_index/_query
Auth
Stack
Planned
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.
Availability
Planned
We plan to add this functionality in a future Elastic Stack update. Subject to changes.
Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.
This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Runs an ES|QL query as the current user. The server applies a space filter and limits the response to at most 1000 rows.
The query determines which indices it reads. Elasticsearch index privileges limit which indices the current user can access.
The space comes from the request URL (/s/{spaceId}/…) or defaults to the default space. The request body cannot change the space or replace the space filter.
Returns a 404 response when Context Engine is turned off in this space (contextEngine:enabled).
For more information, refer to the Context Engine documentation .
Privileges
contextEngine:read
Expand all
space_id
string
optional
An identifier for the space. If space_id is not provided in the URL, the default space is used. Refer to Spaces for more information.
A required header to protect against CSRF attacks
{
}
limit
number · min: 1 · max: 1000
Maximum rows to return. Defaults to 100; a trailing LIMIT in the query is capped to this value.
params
map string to string | number | boolean
Values for ?name placeholders in the query.
query
string · min length: 1 · max length: 10000
required
The ES|QL query to run. Its FROM decides which Elasticsearch indices are read (normally ai-index-*); the server adds the space filter and a row limit.
200
The columns and rows returned by the ES|QL query.
application/json
columns
object []
required
Column metadata for the returned rows.
−
Hide 2 properties
name
string
required
Column name.
type
string
required
Column ES|QL type.
values
object []
required
Row values, aligned positionally with columns, as Elasticsearch returns them. A multi-valued field is an array; _source and flattened columns are objects.
400
The ES|QL query was invalid, or its response exceeded the size limit.
application/json
error
string
The HTTP status text.
message
string
required
A human-readable error message.
statusCode
number
The HTTP status code.
403
Elasticsearch rejected the read; the caller lacks index privileges.
application/json
error
string
The HTTP status text.
message
string
required
A human-readable error message.
statusCode
number
The HTTP status code.
404
Context Engine is turned off in this space.
application/json
error
string
The HTTP status text.
message
string
required
A human-readable error message.
statusCode
number
The HTTP status code.
Thank you for your feedback.
Base URL
https://{kibana_url}
Examples
Example
2 languages
Query with a parameter and a limit
2 languages
Request
Console
1 / 2 languages
‹
›
1
2
3
4
5
6
POST kbn:/api/context_engine/ai_index/_query
{
"query": "FROM ai-index-* | WHERE type == ?type | KEEP title, type, attributes | LIMIT 10",
"params": { "type": "faq" },
"limit": 10
}
1
2
3
4
5
6
7
8
9
10
curl \
-X POST "https://${KIBANA_URL}/api/context_engine/ai_index/_query" \
-H "Authorization: ApiKey ${API_KEY}" \
-H "kbn-xsrf: true" \
-H "Content-Type: application/json" \
-d '{
"query": "FROM ai-index-* | WHERE type == ?type | KEEP title, type, attributes | LIMIT 10",
"params": { "type": "faq" },
"limit": 10
}'
Response
The ES|QL query references a column that does not exist
Show more
The caller lacks Elasticsearch index privileges
Show more
Context Engine is turned off in this space
Show more
1
2
3
4
5
{
"error": "Bad Request",
"message": "verification_exception\n\tRoot causes:\n\t\tverification_exception: Found 1 problem\nline 1:46: Unknown column [titel], did you mean [title]?",
"statusCode": 400
}
1
2
3
4
5
{
"error": "Forbidden",
"message": "security_exception\n\tRoot causes:\n\t\tsecurity_exception: action [indices:data/read/esql] is unauthorized for user [jdoe] with effective roles [support_reader], this action is granted by the index privileges [read_cross_cluster,read,all]",
"statusCode": 403
}
1
2
3
4
5
{
"error": "Not Found",
"message": "Not Found",
"statusCode": 404
}
Request
Console
1 / 2 languages
‹
›
Example ES|QL query with a named parameter and a row limit
Show more
1
2
3
4
5
6
7
8
POST kbn:/api/context_engine/ai_index/_query
{
"limit": 10,
"params": {
"type": "faq"
},
"query": "FROM ai-index-* | WHERE type == ?type | KEEP title, type, attributes | LIMIT 10"
}
Generated from the API spec
1
2
3
4
5
6
7
8
9
10
11
12
curl \
-X POST "https://${KIBANA_URL}/api/context_engine/ai_index/_query" \
-H "Authorization: ApiKey ${API_KEY}" \
-H "kbn-xsrf: true" \
-H "Content-Type: application/json" \
-d '{
"limit": 10,
"params": {
"type": "faq"
},
"query": "FROM ai-index-* | WHERE type == ?type | KEEP title, type, attributes | LIMIT 10"
}'
Generated from the API spec
Response
Example response with column metadata and matching rows. flattened columns such as attributes are returned as objects.
Show more
The ES|QL query references a column that does not exist
Show more
The caller lacks Elasticsearch index privileges
Show more
Context Engine is turned off in this space
Show more
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
"columns": [
{
"name": "title",
"type": "text"
},
{
"name": "type",
"type": "keyword"
},
{
"name": "attributes",
"type": "flattened"
}
],
"values": [
[
"How to reset a password",
"faq",
{
"source": "zendesk"
}
],
[
"Billing cycle explained",
"faq",
{
"source": "zendesk"
}
]
]
}
1
2
3
4
5
{
"error": "Bad Request",
"message": "verification_exception\n\tRoot causes:\n\t\tverification_exception: Found 1 problem\nline 1:46: Unknown column [titel], did you mean [title]?",
"statusCode": 400
}
1
2
3
4
5
{
"error": "Forbidden",
"message": "security_exception\n\tRoot causes:\n\t\tsecurity_exception: action [indices:data/read/esql] is unauthorized for user [jdoe] with effective roles [support_reader], this action is granted by the index privileges [read_cross_cluster,read,all]",
"statusCode": 403
}
1
2
3
4
5
{
"error": "Not Found",
"message": "Not Found",
"statusCode": 404
}