Skip to content

Commit

Permalink
build datastream name from index name
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunian committed Oct 8, 2020
1 parent 1cefc8e commit 5ae3092
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,8 @@ const updateExistingIndex = async ({
delete mappings.properties.stream;
delete mappings.properties.data_stream;

// get the data_stream values from the index template to compose data stream name
const indexMappings = await getIndexMappings(indexName, callCluster);
const dataStream = indexMappings[indexName].mappings.properties.data_stream.properties;
if (!dataStream.type.value || !dataStream.dataset.value || !dataStream.namespace.value)
throw new Error(`data_stream values are missing from the index template ${indexName}`);
const dataStreamName = `${dataStream.type.value}-${dataStream.dataset.value}-${dataStream.namespace.value}`;

const [, dsType, dsTemplateName, dsNamespace] = indexName.split('-');
const dataStreamName = `${dsType}-${dsTemplateName}-${dsNamespace}`;
// try to update the mappings first
try {
await callCluster('indices.putMapping', {
Expand Down Expand Up @@ -438,14 +433,3 @@ const updateExistingIndex = async ({
throw new Error(`could not update index template settings for ${indexName}`);
}
};

const getIndexMappings = async (indexName: string, callCluster: CallESAsCurrentUser) => {
try {
const indexMappings = await callCluster('indices.getMapping', {
index: indexName,
});
return indexMappings;
} catch (err) {
throw new Error(`could not get mapping from ${indexName}`);
}
};

0 comments on commit 5ae3092

Please sign in to comment.