-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Search Apps. - fetch indices one-by-one (#156571)
## Summary fetches a search application's indices' stats one at a time. if even one index is not available the stats api returns an error[^1]. while fetching them all together is probably more efficient we have to get them one-by-one just in case one isn't available. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios [^1]: <details><summary>stats errors response</summary> <pre> { "error": { "root_cause": [ { "type": "index_not_found_exception", "reason": "no such index [sloane-books-001]", "resource.type": "index_or_alias", "resource.id": "sloane-books-001", "index_uuid": "_na_", "index": "sloane-books-001" } ], "type": "index_not_found_exception", "reason": "no such index [sloane-books-001]", "resource.type": "index_or_alias", "resource.id": "sloane-books-001", "index_uuid": "_na_", "index": "sloane-books-001" }, "status": 404 } </pre> </details> (cherry picked from commit 23a45bd)
- Loading branch information
Sloane Perrault
committed
May 3, 2023
1 parent
cde3abf
commit d0e3ca5
Showing
6 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/enterprise_search/server/lib/engines/available_indices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server'; | ||
|
||
export const availableIndices = async ( | ||
client: IScopedClusterClient, | ||
indices: string[] | ||
): Promise<string[]> => { | ||
if (await client.asCurrentUser.indices.exists({ index: indices })) return indices; | ||
|
||
const indicesAndExists: Array<[string, boolean]> = await Promise.all( | ||
indices.map(async (index) => [index, await client.asCurrentUser.indices.exists({ index })]) | ||
); | ||
return indicesAndExists.flatMap(([index, exists]) => (exists ? [index] : [])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters