Find users with a query

  • POST also GET /_security/_query/user
Auth

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.

Required authorization

Cluster privileges read_security

Query parameters

with_profile_uid boolean · default: false

Determines whether to retrieve the user profile UID, if it exists, for the users.

Request body

query object

A query to filter which users to return. If the query parameter is missing, it is equivalent to a match_all query. The query supports a subset of query types, including match_all, bool, term, terms, match, ids, prefix, wildcard, exists, range, and simple_query_string. You can query the following information associated with user: username, roles, enabled, full_name, and email.

ids object

Returns users based on their IDs. This query uses the user document IDs stored in the _id field.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
values union oneOf

An array of document IDs.

One of: string[] or string
bool object

matches users matching boolean combinations of other queries.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
filter union oneOf

The clause (query) must appear in matching documents. However, unlike must, the score of the query will be ignored.

One of: Query[] or Query
minimum_should_match number | string

Specifies the number or percentage of should clauses returned documents must match.

must union oneOf

The clause (query) must appear in matching documents and will contribute to the score.

One of: Query[] or Query
must_not union oneOf

The clause (query) must not appear in the matching documents. Because scoring is ignored, a score of 0 is returned for all documents.

One of: Query[] or Query
should union oneOf

The clause (query) should appear in the matching document.

One of: Query[] or Query
exists object

Returns users that contain an indexed value for a field.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
field string required

Name of the field you wish to search.

match map string to object · min properties: 1 · max properties: 1

Returns users that match a provided text, number, date or boolean value. The provided text is analyzed before matching.

<string> object
boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
analyzer string

Analyzer used to convert the text in the query value into tokens.

auto_generate_synonyms_phrase_query boolean · default: true

If true, match phrase queries are automatically created for multi-term synonyms.

cutoff_frequency number deprecated
fuzziness number | string

Maximum edit distance allowed for matching.

fuzzy_rewrite string

Method used to rewrite the query.

fuzzy_transpositions boolean · default: true

If true, edits for fuzzy matching include transpositions of two adjacent characters (for example, ab to ba).

lenient boolean · default: false

If true, format-based errors, such as providing a text query value for a numeric field, are ignored.

max_expansions number · default: 50

Maximum number of terms to which the query will expand.

minimum_should_match number | string

Minimum number of clauses that must match for a document to be returned.

operator enum · default: 'or'

Boolean logic used to interpret text in the query value.

Values: and AND or OR
prefix_length number · default: 0

Number of beginning characters left unchanged for fuzzy matching.

query boolean | number | string required

Text, number, boolean value or date you wish to find in the provided field.

zero_terms_query enum · default: 'none'

Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a stop filter.

Supported values include:

  • all: Returns all documents, similar to a match_all query.
  • none: No documents are returned if the analyzer removes all tokens.
Values: all none
match_all object

Matches all users, giving them all a _score of 1.0.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
prefix map string to object · min properties: 1 · max properties: 1

Returns users that contain a specific prefix in a provided field.

<string> object
boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
rewrite string

Method used to rewrite the query.

value string required

Beginning characters of terms you wish to find in the provided field.

case_insensitive boolean · default: false

Allows ASCII case insensitive matching of the value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping.

range map string to oneOf · min properties: 1 · max properties: 1

Returns users that contain terms within a provided range.

simple_query_string object

Returns users based on a provided query string, using a parser with a limited but fault-tolerant syntax.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
analyzer string

Analyzer used to convert text in the query string into tokens.

analyze_wildcard boolean · default: false

If true, the query attempts to analyze wildcard terms in the query string.

auto_generate_synonyms_phrase_query boolean · default: true

If true, the parser creates a match_phrase query for each multi-position token.

default_operator enum · default: 'or'

Default boolean logic used to interpret text in the query string if no operators are specified.

Values: and AND or OR
fields string[]

Array of fields you wish to search. Accepts wildcard expressions. You also can boost relevance scores for matches to particular fields using a caret (^) notation. Defaults to the index.query.default_field index setting, which has a default value of *.

flags union · default: ALL

List of enabled operators for the simple query string syntax.

Values: NONE AND NOT OR PREFIX PHRASE PRECEDENCE ESCAPE WHITESPACE FUZZY NEAR SLOP ALL
fuzzy_max_expansions number · default: 50

Maximum number of terms to which the query expands for fuzzy matching.

fuzzy_prefix_length number · default: 0

Number of beginning characters left unchanged for fuzzy matching.

fuzzy_transpositions boolean

If true, edits for fuzzy matching include transpositions of two adjacent characters (for example, ab to ba).

lenient boolean · default: false

If true, format-based errors, such as providing a text value for a numeric field, are ignored.

minimum_should_match number | string

Minimum number of clauses that must match for a document to be returned.

query string required

Query string in the simple query string syntax you wish to parse and use for search.

quote_field_suffix string

Suffix appended to quoted text in the query string.

term map string to object · min properties: 1 · max properties: 1

Returns users that contain an exact term in a provided field. To return a document, the query term must exactly match the queried field's value, including whitespace and capitalization.

<string> object
boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
value union oneOf required

Term you wish to find in the provided field.

One of: number or string or boolean or object
case_insensitive boolean · default: false

Allows ASCII case insensitive matching of the value with the indexed field values when set to true. When false, the case sensitivity of matching depends on the underlying field’s mapping.

terms object

Returns users that contain one or more exact terms in a provided field. To return a document, one or more terms must exactly match a field value, including whitespace and capitalization.

boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
wildcard map string to object · min properties: 1 · max properties: 1

Returns users that contain terms matching a wildcard pattern.

<string> object
boost number · default: 1

Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

_name string
case_insensitive boolean

Allows case insensitive matching of the pattern with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping.

rewrite string

Method used to rewrite the query.

value string

Wildcard pattern for terms you wish to find in the provided field. Required, when wildcard is not set.

wildcard string

Wildcard pattern for terms you wish to find in the provided field. Required, when value is not set.

from number · default: 0

The starting document offset. It must not be negative. By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter.

sort union oneOf

The sort definition. Fields eligible for sorting are: username, roles, enabled. In addition, sort can also be applied to the _doc field to sort by index order.

A value or an array; each item is one of:

Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

size number · default: 10

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 and size parameters. To page through more hits, use the search_after parameter.

search_after union[]

The search after definition

Response

application/json
total number required

The total number of users found.

count number required

The number of users returned in the response.

users object[] required

A list of users that match the query.

email union string nullable
One of: string
full_name union string nullable
metadata object required
roles string[] required
username string required
enabled boolean required
profile_uid string
_sort union[]