dsl-builder
Version:
OpenSearch Query Builder - Extract from OpenSearch Dashboards
27 lines (26 loc) • 1.22 kB
JavaScript
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import { concatDataSourceWithIndexPattern, getIndexPatternTitle, getDataSourceReference, } from '../utils';
export async function getTitle(client, indexPatternId, dataSourceIdToTitle) {
const savedObject = (await client.get('index-pattern', indexPatternId));
if (savedObject.error) {
throw new Error(`Unable to get index-pattern title: ${savedObject.error.message}`);
}
const dataSourceReference = getDataSourceReference(savedObject.references);
if (dataSourceReference) {
const dataSourceId = dataSourceReference.id;
if (dataSourceIdToTitle.has(dataSourceId)) {
return concatDataSourceWithIndexPattern(dataSourceIdToTitle.get(dataSourceId), savedObject.attributes.title);
}
}
const getDataSource = async (id) => await client.get('data-source', id);
return getIndexPatternTitle(savedObject.attributes.title, savedObject.references, getDataSource);
}