Skip to content
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

[Ingest] fix api endpoint and throw error #65790

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
};