Find users with a query
Generally available; Added in 8.14.0
All methods and paths for this operation:
Get information for users in a paginated manner. You can optionally filter the results with a query.
NOTE: As opposed to the get user API, built-in users are excluded from the result. This API is only for native users.
highlight#highlightFromAnchor" href="#topic-required-authorization"> Required authorization
- Cluster privileges:
read_security
Body
-
The starting document offset. It must not be negative. By default, you cannot page through more than 10,000 hits using the
from
andsize
parameters. To page through more hits, use thesearch_after
parameter.Default value is
0
. sort
string | object | array[string | object] alternative#change alternative:form->explorer-send-request#updateRequest" data-tabs-scroll="true">One of: tabs#change click->alternative#change " data-tabs-target="tab" href="#operation-security-query-user-body-application-json" role="tab" aria-controls="operation-security-query-user-body-application-json" tabindex="0"> Fieldstring tabs#change click->alternative#change " data-tabs-target="tab" href="#operation-security-query-user-body-application-json-sortoptions-object" role="tab" aria-controls="operation-security-query-user-body-application-json-sortoptions-object" tabindex="0"> SortOptionsobject tabs#change click->alternative#change " data-tabs-target="tab" href="#operation-security-query-user-body-application-json-array-2-array-string-object" role="tab" aria-controls="operation-security-query-user-body-application-json-array-2-array-string-object" tabindex="0"> array-2array[string | object] Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
alternative#change alternative:form->explorer-send-request#updateRequest" data-tabs-scroll="true">One of: tabs#change click->alternative#change " data-tabs-target="tab" href="#operation-security-query-user-body-application-json-array-2-array-string-object" role="tab" aria-controls="operation-security-query-user-body-application-json-array-2-array-string-object" tabindex="0"> Fieldstring tabs#change click->alternative#change " data-tabs-target="tab" href="#operation-security-query-user-body-application-json-array-2-array-string-object-sortoptions-object" role="tab" aria-controls="operation-security-query-user-body-application-json-array-2-array-string-object-sortoptions-object" tabindex="0"> SortOptionsobject Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
The number of hits to return. It must not be negative. By default, you cannot page through more than 10,000 hits using the
from
andsize
parameters. To page through more hits, use thesearch_after
parameter.Default value is
10
. -
A field value.
POST /_security/_query/user?with_profile_uid=true
{
"query": {
"prefix": {
"roles": "other"
}
}
}
resp = client.security.query_user(
with_profile_uid=True,
query={
"prefix": {
"roles": "other"
}
},
)
const response = await client.security.queryUser({
with_profile_uid: "true",
query: {
prefix: {
roles: "other",
},
},
});
response = client.security.query_user(
with_profile_uid: "true",
body: {
"query": {
"prefix": {
"roles": "other"
}
}
}
)
$resp = $client->security()->queryUser([
"with_profile_uid" => "true",
"body" => [
"query" => [
"prefix" => [
"roles" => "other",
],
],
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"query":{"prefix":{"roles":"other"}}}' "$ELASTICSEARCH_URL/_security/_query/user?with_profile_uid=true"
client.security().queryUser(q -> q
.query(qu -> qu
.prefix(p -> p
.field("roles")
.value("other")
)
)
.withProfileUid(true)
);
{
"query": {
"prefix": {
"roles": "other"
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"email": "*example.com"
}
},
{
"term": {
"enabled": true
}
}
],
"filter": [
{
"wildcard": {
"roles": "*other*"
}
}
]
}
},
"from": 1,
"size": 2,
"sort": [
{ "username": { "order": "desc"} }
]
}
{
"total": 1,
"count": 1,
"users": [
{
"username": "jacknich",
"roles": [
"admin",
"other_role1"
],
"full_name": "Jack Nicholson",
"email": "jacknich@example.com",
"metadata": {
"intelligence": 7
},
"enabled": true,
"profile_uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0"
}
]
}
{
"total": 5,
"count": 2,
"users": [
{
"username": "ray",
"roles": [
"other_role3"
],
"full_name": "Ray Nicholson",
"email": "rayn@example.com",
"metadata": {
"intelligence": 7
},
"enabled": true,
"_sort": [
"ray"
]
},
{
"username": "lorraine",
"roles": [
"other_role3"
],
"full_name": "Lorraine Nicholson",
"email": "lorraine@example.com",
"metadata": {
"intelligence": 7
},
"enabled": true,
"_sort": [
"lorraine"
]
}
]
}
{
"total": 2,
"count": 2,
"users": [
{
"username": "jacknich",
"roles": [
"admin",
"other_role1"
],
"full_name": "Jack Nicholson",
"email": "jacknich@example.com",
"metadata": {
"intelligence": 7
},
"enabled": true
},
{
"username": "sandrakn",
"roles": [
"admin",
"other_role1"
],
"full_name": "Sandra Knight",
"email": "sandrakn@example.com",
"metadata": {
"intelligence": 7
},
"enabled": true
}
]
}