Spaces method and path for this operation:
post /s/{space_id}/api/osquery/saved_queries
Refer to Spaces for more information.
Create and save a query for later use.
Body
Required
-
The saved query description.
-
Map osquery results columns or static values to Elastic Common Schema (ECS) fields
-
The ID of a saved query.
-
An interval, in seconds, on which to run the query.
-
Restricts the query to a specified platform. The default is all platforms. To specify multiple platforms, use commas. For example,
linux,darwin. -
The SQL query you want to run.
-
Indicates whether the query is removed.
-
Indicates whether the query is a snapshot.
-
Uses the Osquery versions greater than or equal to the specified version string.
POST
/api/osquery/saved_queries
curl \
--request POST 'https://localhost:5601/api/osquery/saved_queries' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--data '"{\n \"description\": \"Saved query description\",\n \"ecs_mapping\": {\n \"host.uptime\": {\n \"field\": \"total_seconds\"\n }\n },\n \"id\": \"my_saved_query\",\n \"interval\": \"60\",\n \"platform\": \"linux,darwin\",\n \"query\": \"select * from uptime;\",\n \"timeout\": 120\n}"'
Request example
{
"description": "Saved query description",
"ecs_mapping": {
"host.uptime": {
"field": "total_seconds"
}
},
"id": "my_saved_query",
"interval": "60",
"platform": "linux,darwin",
"query": "select * from uptime;",
"timeout": 120
}
Response examples (200)
{
"data": {
"created_at": "2025-02-26T13:37:30.452Z",
"created_by": "elastic",
"description": "Saved query description",
"ecs_mapping": {
"host.uptime": {
"field": "total_seconds"
}
},
"id": "my_saved_query",
"interval": "60",
"platform": "linux,darwin",
"query": "select * from uptime;",
"saved_object_id": "42ba1280-2172-11ee-8523-5765fca79a3c",
"timeout": 120,
"updated_at": "2025-02-26T13:37:30.452Z",
"updated_by": "elastic"
}
}