2017-08-24 22:33:28 +00:00
|
|
|
---
|
|
|
|
layout: api
|
|
|
|
page_title: Search - HTTP API
|
2020-02-06 23:45:31 +00:00
|
|
|
sidebar_title: Search
|
|
|
|
description: The /search endpoint is used to search for Nomad objects
|
2017-08-24 22:33:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Search HTTP API
|
|
|
|
|
|
|
|
The `/search` endpoint returns matches for a given prefix and context, where a
|
2020-04-21 12:33:24 +00:00
|
|
|
context can be jobs, allocations, evaluations, nodes, deployments, plugins,
|
|
|
|
or volumes. When using Nomad Enterprise, the allowed contexts include quotas
|
|
|
|
and namespaces. Additionally, a prefix can be searched for within every context.
|
2017-08-24 22:33:28 +00:00
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
| Method | Path | Produces |
|
|
|
|
| ------ | ------------ | ------------------ |
|
|
|
|
| `POST` | `/v1/search` | `application/json` |
|
2017-08-24 22:33:28 +00:00
|
|
|
|
|
|
|
The table below shows this endpoint's support for
|
2020-03-20 22:24:56 +00:00
|
|
|
[blocking queries](/api-docs#blocking-queries) and
|
|
|
|
[required ACLs](/api-docs#acls).
|
2017-08-24 22:33:28 +00:00
|
|
|
|
2017-10-10 22:04:23 +00:00
|
|
|
| Blocking Queries | ACL Required |
|
|
|
|
| ---------------- | -------------------------------- |
|
|
|
|
| `NO` | `node:read, namespace:read-jobs` |
|
|
|
|
|
|
|
|
When ACLs are enabled, requests must have a token valid for `node:read` or
|
|
|
|
`namespace:read-jobs` roles. If the token is only valid for `node:read`, then
|
|
|
|
job related results will not be returned. If the token is only valid for
|
|
|
|
`namespace:read-jobs`, then node results will not be returned.
|
2017-08-24 22:33:28 +00:00
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
2019-05-08 16:54:44 +00:00
|
|
|
- `Prefix` `(string: <required>)` - Specifies the identifier against which
|
2017-08-24 22:33:28 +00:00
|
|
|
matches will be found. For example, if the given prefix were "a", potential
|
|
|
|
matches might be "abcd", or "aabb".
|
|
|
|
- `Context` `(string: <required>)` - Defines the scope in which a search for a
|
|
|
|
prefix operates. Contexts can be: "jobs", "evals", "allocs", "nodes",
|
2020-04-21 12:33:24 +00:00
|
|
|
"deployment", "plugins", "volumes" or "all", where "all" means every
|
|
|
|
context will be searched.
|
2017-08-24 22:33:28 +00:00
|
|
|
|
2020-04-21 12:33:24 +00:00
|
|
|
### Sample Payload (for all contexts)
|
2017-08-24 22:33:28 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"Prefix": "abc",
|
2020-04-21 12:33:24 +00:00
|
|
|
"Context": "all"
|
2017-08-24 22:33:28 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Sample Request
|
|
|
|
|
2020-05-18 20:53:06 +00:00
|
|
|
```shell-session
|
|
|
|
$ curl \
|
2017-08-24 22:33:28 +00:00
|
|
|
--request POST \
|
|
|
|
--data @payload.json \
|
2018-01-29 16:27:52 +00:00
|
|
|
https://localhost:4646/v1/search
|
2017-08-24 22:33:28 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Sample Response
|
|
|
|
|
|
|
|
```json
|
2020-02-06 23:45:31 +00:00
|
|
|
{
|
|
|
|
"Matches": {
|
2020-04-21 12:33:24 +00:00
|
|
|
"allocs": null,
|
|
|
|
"deployment": null,
|
|
|
|
"evals": ["abc2fdc0-e1fd-2536-67d8-43af8ca798ac"],
|
|
|
|
"jobs": ["abcde"],
|
|
|
|
"nodes": null,
|
|
|
|
"plugins": null,
|
|
|
|
"volumes": null
|
2017-08-24 22:33:28 +00:00
|
|
|
},
|
|
|
|
"Truncations": {
|
2020-04-21 12:33:24 +00:00
|
|
|
"allocs": "false",
|
|
|
|
"deployment": "false",
|
|
|
|
"evals": "false",
|
|
|
|
"jobs": "false",
|
|
|
|
"nodes": "false",
|
|
|
|
"plugins": "false",
|
|
|
|
"volumes": "false"
|
2017-08-24 22:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-04-21 12:33:24 +00:00
|
|
|
#### Field Reference
|
|
|
|
|
|
|
|
- `Matches` - A map of contexts to matching arrays of identifiers.
|
|
|
|
|
|
|
|
- `Truncations` - Search results are capped at 20; if more matches were found for a particular context, it will be `true`.
|
|
|
|
|
|
|
|
### Sample Payload (for a specific context)
|
2017-08-24 22:33:28 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"Prefix": "abc",
|
2020-04-21 12:33:24 +00:00
|
|
|
"Context": "evals"
|
2017-08-24 22:33:28 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Sample Request
|
|
|
|
|
2020-05-18 20:53:06 +00:00
|
|
|
```shell-session
|
|
|
|
$ curl \
|
2017-08-24 22:33:28 +00:00
|
|
|
--request POST \
|
|
|
|
--data @payload.json \
|
2018-01-29 16:27:52 +00:00
|
|
|
https://localhost:4646/v1/search
|
2017-08-24 22:33:28 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Sample Response
|
|
|
|
|
|
|
|
```json
|
2020-02-06 23:45:31 +00:00
|
|
|
{
|
|
|
|
"Matches": {
|
2020-04-21 12:33:24 +00:00
|
|
|
"evals": ["abc2fdc0-e1fd-2536-67d8-43af8ca798ac"]
|
2017-08-24 22:33:28 +00:00
|
|
|
},
|
|
|
|
"Truncations": {
|
2020-04-21 12:33:24 +00:00
|
|
|
"evals": "false"
|
2017-08-24 22:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|