Skip to content

Commit

Permalink
change api endpoint and throw error (#65790)
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunian committed May 8, 2020
1 parent 37aad5c commit 8ba44eb
Showing 1 changed file with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) =>
Promise.all(
Object.keys(IndexPatternType).map(async indexPattern => {
const defaultIndexPatternName = indexPattern + INDEX_PATTERN_PLACEHOLDER_SUFFIX;
const indexExists = await doesIndexExist(defaultIndexPatternName, callCluster);
const indexExists = await callCluster('indices.exists', { index: defaultIndexPatternName });
if (!indexExists) {
try {
await callCluster('transport.request', {
method: 'PUT',
path: `/${defaultIndexPatternName}`,
await callCluster('indices.create', {
index: defaultIndexPatternName,
body: {
mappings: {
properties: {
Expand All @@ -387,20 +386,9 @@ export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) =>
},
});
} catch (putErr) {
throw new Error(`${defaultIndexPatternName} could not be created`);
// throw new Error(`${defaultIndexPatternName} could not be created`);
throw new Error(putErr);
}
}
})
);

export const doesIndexExist = async (indexName: string, callCluster: CallESAsCurrentUser) => {
try {
await callCluster('transport.request', {
method: 'HEAD',
path: indexName,
});
return true;
} catch (err) {
return false;
}
};

0 comments on commit 8ba44eb

Please sign in to comment.