-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sort and pagination support for QueryApiKey API #76144
Conversation
This PR adds support for sort and pagination similar to those used with regular search API. Similar to the query field, the sort field also supports only a subset of what is available for regular search.
Pinging @elastic/es-security (Team:Security) |
private boolean filterForCurrentUser; | ||
|
||
public QueryApiKeyRequest() { | ||
this((QueryBuilder) null); | ||
} | ||
|
||
public QueryApiKeyRequest(QueryBuilder queryBuilder) { | ||
this.queryBuilder = queryBuilder; | ||
this(queryBuilder, -1, -1, null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default size
is -1, which means it will use the default value from regular search, ie. 10
. We could bump this to a higher value, but I think it also has value to be consistent with the default search behaviour.
.field("total", total) | ||
.field("count", foundApiKeysInfo.length) | ||
.array("api_keys", (Object[]) foundApiKeysInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add a sort
field here in the response because adding it would make the response look less pleasing, i.e. it would be
{ "api_key": [ {"api_key":{...}, "sort":[...]}, {} ] }
instead of just
{ "api_key": [ {...}, {...} ] }
When sort
is not required, the more nested version looks even more unnecessary. Also, unlike regular search response, all sort values are present in the response (api_key
) already since there will be no filtering. So the information can be readliy parsed from each api_key item.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised there is one minor caveat of not showing sort values: They can have different formats than the original value. For example, creation_time
can be formatted to be more human readable. So instead of
"sort": [ 1626237059434 ]
it will be the following more human readable format
"sort" : [ "2021-07-14T04:30:59.434Z" ]
Note this difference does not seem to affect how search_after
works. That is, you can pass specify either "search_after": [1626237059434]
or "search_after": ["2021-07-14T04:30:59.434Z"]
and they both work.
In general, while the human readable format of sort values is nice to have, I don't think it is worth to complicate the response especially since search_after
does not get impacted.
One question that probably should have been raised earlier in the process:
|
This is a good question. Thanks for bringing this up. I didn't support I think we have a few options to consider:
My preference is Option 2 because:
Option 3 is a close call. It has the benefit of not using |
Also it is unfortunate that we cannot use runtime field because it requires
can easily solve the dilemma here. I remember there were previous asks about whether it is possible to always allow expensive queries for internal actions regardless of |
Are we sure we want to support sorting on The latest docs no longer have this section, but the pre-PIT docs for |
Errr Great infomation. It is also documented here. In this case, no, we should not sort on it. PIT always needs tiebreaker and for that it has a concept of So supporting
|
Another option is to just return the
but it's a bit weird to be different for the sake of being different ... |
My preference would probably be:
but I'm open to the other options too. |
I am ok with |
@tvernum Thanks for the comments. The PR is now updated based on our discussion:
|
final int from = randomIntBetween(0, 3); | ||
final int size = randomIntBetween(2, 5); | ||
final int remaining = total - from; | ||
final String sortField = randomFrom("name", "creation"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doens't this assume that no to API keys have the same creation time?
Are we sure that's always going to be true in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added _doc
as a 2nd sort field. Since keys are created sequential and with wait_for
, I don't think it is possible to have the same creation time. But it's a good place to exercise _doc
some more and is more future proof (e.g. keys may be created in parallel).
This PR adds support for sort and pagination similar to those used with regular search API. Similar to the query field, the sort field also supports only a subset of what is available for regular search.
This PR adds HLRC for the new Query API key API added with elastic#75335 and elastic#76144 Relates: elastic#71023
This PR adds documentation for the new QueryApiKey API added in elastic#75335 and elastic#76144 Relates: elastic#71023
This PR adds documentation for the new QueryApiKey API added in elastic#75335 and elastic#76144 Relates: elastic#71023
This PR adds support for sort and pagination similar to those used with
regular search API. Similar to the query field, the sort field also
supports only a subset of what is available for regular search.
Relates: #71023