-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add sort and pagination support for QueryApiKey API #76144
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
Changes from 1 commit
a25bd76
f10ea81
0a6c326
d17c873
9fff053
a67ef8a
6c39402
c7ad161
381c160
c8766ec
309f2af
ef90dfd
7b9a2af
da3dea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,20 +27,27 @@ | |
| */ | ||
| public final class QueryApiKeyResponse extends ActionResponse implements ToXContentObject, Writeable { | ||
|
|
||
| private final long total; | ||
| private final ApiKey[] foundApiKeysInfo; | ||
|
|
||
| public QueryApiKeyResponse(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.total = in.readLong(); | ||
| this.foundApiKeysInfo = in.readArray(ApiKey::new, ApiKey[]::new); | ||
| } | ||
|
|
||
| public QueryApiKeyResponse(Collection<ApiKey> foundApiKeysInfo) { | ||
| public QueryApiKeyResponse(long total, Collection<ApiKey> foundApiKeysInfo) { | ||
| this.total = total; | ||
| Objects.requireNonNull(foundApiKeysInfo, "found_api_keys_info must be provided"); | ||
| this.foundApiKeysInfo = foundApiKeysInfo.toArray(new ApiKey[0]); | ||
| } | ||
|
|
||
| public static QueryApiKeyResponse emptyResponse() { | ||
| return new QueryApiKeyResponse(Collections.emptyList()); | ||
| return new QueryApiKeyResponse(0, Collections.emptyList()); | ||
| } | ||
|
|
||
| public long getTotal() { | ||
| return total; | ||
| } | ||
|
|
||
| public ApiKey[] getApiKeyInfos() { | ||
|
|
@@ -50,12 +57,15 @@ public ApiKey[] getApiKeyInfos() { | |
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject() | ||
| .field("total", total) | ||
| .field("count", foundApiKeysInfo.length) | ||
| .array("api_keys", (Object[]) foundApiKeysInfo); | ||
|
||
| return builder.endObject(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeLong(total); | ||
| out.writeArray(foundApiKeysInfo); | ||
| } | ||
|
|
||
|
|
@@ -66,17 +76,18 @@ public boolean equals(Object o) { | |
| if (o == null || getClass() != o.getClass()) | ||
| return false; | ||
| QueryApiKeyResponse that = (QueryApiKeyResponse) o; | ||
| return Arrays.equals(foundApiKeysInfo, that.foundApiKeysInfo); | ||
| return total == that.total && Arrays.equals(foundApiKeysInfo, that.foundApiKeysInfo); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Arrays.hashCode(foundApiKeysInfo); | ||
| int result = Objects.hash(total); | ||
| result = 31 * result + Arrays.hashCode(foundApiKeysInfo); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "QueryApiKeyResponse [foundApiKeysInfo=" + foundApiKeysInfo + "]"; | ||
| return "QueryApiKeyResponse{" + "total=" + total + ", foundApiKeysInfo=" + Arrays.toString(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.
Default
sizeis -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.