Skip to content

Commit 8c91998

Browse files
Add specification for query users (#2684) (#2700)
* Add specification for query users (cherry picked from commit ab1e338) Co-authored-by: Johannes Fredén <[email protected]>
1 parent 53c37ff commit 8c91998

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { UserQueryContainer } from './types'
21+
import { RequestBase } from '@_types/Base'
22+
import { integer } from '@_types/Numeric'
23+
import { Sort, SortResults } from '@_types/sort'
24+
25+
/**
26+
* Retrieves information for Users in a paginated manner. You can optionally filter the results with a query.
27+
* @rest_spec_name security.query_user
28+
* @availability stack since=8.14.0 stability=stable
29+
* @availability serverless stability=stable visibility=private
30+
* @cluster_privileges read_security
31+
*/
32+
export interface Request extends RequestBase {
33+
body: {
34+
/**
35+
* A query to filter which users to return.
36+
* If the query parameter is missing, it is equivalent to a `match_all` query.
37+
* The query supports a subset of query types, including `match_all`, `bool`, `term`, `terms`, `match`,
38+
* `ids`, `prefix`, `wildcard`, `exists`, `range`, and `simple_query_string`.
39+
* You can query the following information associated with user: `username`, `roles`, `enabled`
40+
*/
41+
query?: UserQueryContainer
42+
/**
43+
* Starting document offset.
44+
* By default, you cannot page through more than 10,000 hits using the from and size parameters.
45+
* To page through more hits, use the `search_after` parameter.
46+
* @server_default 0
47+
*/
48+
from?: integer
49+
/**
50+
* Fields eligible for sorting are: username, roles, enabled
51+
* In addition, sort can also be applied to the `_doc` field to sort by index order.
52+
* @doc_id sort-search-results */
53+
sort?: Sort
54+
/**
55+
* The number of hits to return.
56+
* By default, you cannot page through more than 10,000 hits using the `from` and `size` parameters.
57+
* To page through more hits, use the `search_after` parameter.
58+
* @server_default 10
59+
*/
60+
size?: integer
61+
/**
62+
* Search after definition
63+
*/
64+
search_after?: SortResults
65+
}
66+
query_parameters: {
67+
/**
68+
* If true will return the User Profile ID for the users in the query result, if any.
69+
*/
70+
with_profile_uid?: boolean
71+
}
72+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { integer } from '@_types/Numeric'
21+
import { QueryUser } from '@security/query_user/types'
22+
23+
export class Response {
24+
body: {
25+
/**
26+
* The total number of users found.
27+
*/
28+
total: integer
29+
/**
30+
* The number of users returned in the response.
31+
*/
32+
count: integer
33+
/**
34+
* A list of user information.
35+
*/
36+
users: QueryUser[]
37+
}
38+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { SingleKeyDictionary } from '@spec_utils/Dictionary'
21+
import { Field } from '@_types/common'
22+
import { BoolQuery } from '@_types/query_dsl/compound'
23+
import { SortResults } from '@_types/sort'
24+
import {
25+
ExistsQuery,
26+
IdsQuery,
27+
PrefixQuery,
28+
RangeQuery,
29+
TermQuery,
30+
TermsQuery,
31+
WildcardQuery
32+
} from '@_types/query_dsl/term'
33+
import { MatchQuery, SimpleQueryStringQuery } from '@_types/query_dsl/fulltext'
34+
import { MatchAllQuery } from '@_types/query_dsl/MatchAllQuery'
35+
import { User } from '@security/_types/User'
36+
37+
/**
38+
* @variants container
39+
* @non_exhaustive
40+
*/
41+
export class UserQueryContainer {
42+
/**
43+
* Returns users based on their IDs.
44+
* This query uses the user document IDs stored in the `_id` field.
45+
* @doc_id query-dsl-ids-query
46+
*/
47+
ids?: IdsQuery
48+
/**
49+
* matches users matching boolean combinations of other queries.
50+
* @doc_id query-dsl-bool-query
51+
*/
52+
bool?: BoolQuery
53+
/**
54+
* Returns users that contain an indexed value for a field.
55+
* @doc_id query-dsl-exists-query
56+
*/
57+
exists?: ExistsQuery
58+
/**
59+
* Returns users that match a provided text, number, date or boolean value.
60+
* The provided text is analyzed before matching.
61+
* @doc_id query-dsl-match-query
62+
*/
63+
match?: SingleKeyDictionary<Field, MatchQuery>
64+
/**
65+
* Matches all users, giving them all a `_score` of 1.0.
66+
* @doc_id query-dsl-match-all-query
67+
*/
68+
match_all?: MatchAllQuery
69+
/**
70+
* Returns users that contain a specific prefix in a provided field.
71+
* @doc_id query-dsl-prefix-query
72+
*/
73+
prefix?: SingleKeyDictionary<Field, PrefixQuery>
74+
/**
75+
* Returns users that contain terms within a provided range.
76+
* @doc_id query-dsl-range-query
77+
*/
78+
range?: SingleKeyDictionary<Field, RangeQuery>
79+
/**
80+
* Returns users based on a provided query string, using a parser with a limited but fault-tolerant syntax.
81+
* @doc_id query-dsl-simple-query-string-query
82+
*/
83+
simple_query_string?: SimpleQueryStringQuery
84+
/**
85+
* Returns users that contain an exact term in a provided field.
86+
* To return a document, the query term must exactly match the queried field's value, including whitespace and capitalization.
87+
* @doc_id query-dsl-term-query
88+
*/
89+
term?: SingleKeyDictionary<Field, TermQuery>
90+
/**
91+
* Returns users that contain one or more exact terms in a provided field.
92+
* To return a document, one or more terms must exactly match a field value, including whitespace and capitalization.
93+
* @doc_id query-dsl-terms-query
94+
*/
95+
terms?: TermsQuery
96+
/**
97+
* Returns users that contain terms matching a wildcard pattern.
98+
* @doc_id query-dsl-wildcard-query
99+
*/
100+
wildcard?: SingleKeyDictionary<Field, WildcardQuery>
101+
}
102+
103+
export class QueryUser extends User {
104+
_sort?: SortResults
105+
}

0 commit comments

Comments
 (0)