Skip to content

Commit 786e4db

Browse files
authored
[EPM] Cleanup ILM loading (#52632)
Before the check for the ILM policy to exist triggered an exception. With this change it is a normal response also if the policy does not exist yet. A follow up issue will be created in Elasticsearch to get a HEAD request for this available.
1 parent 328474a commit 786e4db

File tree

1 file changed

+6
-12
lines changed
  • x-pack/legacy/plugins/epm/server/lib/elasticsearch/ilm

1 file changed

+6
-12
lines changed

x-pack/legacy/plugins/epm/server/lib/elasticsearch/ilm/install.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ export async function policyExists(
2525
name: string,
2626
callCluster: CallESAsCurrentUser
2727
): Promise<boolean> {
28-
try {
29-
// TODO: Figure out if there is a better way to check for an ILM policy to exist that
30-
// does not throw an exception.
31-
await callCluster('transport.request', {
32-
method: 'GET',
33-
path: '/_ilm/policy/' + name,
34-
});
35-
return true;
36-
} catch (e) {
37-
return false;
38-
}
28+
const response = await callCluster('transport.request', {
29+
method: 'GET',
30+
path: '/_ilm/policy/?filter_path=' + name,
31+
});
3932

40-
return false;
33+
// If the response contains a key, it means the policy exists
34+
return Object.keys(response).length > 0;
4135
}

0 commit comments

Comments
 (0)