Skip to content

Commit

Permalink
[ML] Fixing data view search based on title (#120737)
Browse files Browse the repository at this point in the history
* [ML] Fixing data view search based on title

* removing size argument
  • Loading branch information
jgowdyelastic authored Dec 8, 2021
1 parent ad6c22d commit dca141c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions x-pack/plugins/ml/public/application/util/index_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ export async function getDataViewIdFromName(name: string): Promise<string | null
if (dataViewsContract === null) {
throw new Error('Data views are not initialized!');
}
const [dv] = await dataViewsContract?.find(name);
if (!dv) {
const dataViews = await dataViewsContract.find(name);
const dataView = dataViews.find(({ title }) => title === name);
if (!dataView) {
return null;
}
return dv.id ?? dv.title;
return dataView.id ?? dataView.title;
}

export function getDataViewById(id: string): Promise<DataView> {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/ml/server/lib/alerts/alerting_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export function alertingServiceProvider(
try {
const dataViewsService = await getDataViewsService();

const dataView = (await dataViewsService.find(indexPattern, 1))[0];
const dataViews = await dataViewsService.find(indexPattern);
const dataView = dataViews.find(({ title }) => title === indexPattern);

if (!dataView) return;

return dataView.fieldFormatMap;
Expand Down

0 comments on commit dca141c

Please sign in to comment.