Skip to content
Merged
Show file tree
Hide file tree
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 @@ -236,26 +236,26 @@ class LinksMenuUI extends Component {
let i = 0;
findFieldType(datafeedIndices[i]);

function findFieldType(index) {
getFieldTypeFromMapping(index, categorizationFieldName)
.then(resp => {
if (resp !== '') {
createAndOpenUrl(index, resp);
} else {
i++;
if (i < datafeedIndices.length) {
findFieldType(datafeedIndices[i]);
} else {
error();
}
}
const error = () => {
console.log(
`viewExamples(): error finding type of field ${categorizationFieldName} in indices:`,
datafeedIndices
);
const { toasts } = this.props.kibana.services.notifications;
toasts.addDanger(
i18n.translate('xpack.ml.anomaliesTable.linksMenu.noMappingCouldBeFoundErrorMessage', {
defaultMessage:
'Unable to view examples of documents with mlcategory {categoryId} ' +
'as no mapping could be found for the categorization field {categorizationFieldName}',
values: {
categoryId,
categorizationFieldName,
},
})
.catch(() => {
error();
});
}
);
};

function createAndOpenUrl(index, categorizationFieldType) {
const createAndOpenUrl = (index, categorizationFieldType) => {
// Find the ID of the index pattern with a title attribute which matches the
// index configured in the datafeed. If a Kibana index pattern has not been created
// for this index, then the user will see a warning message on the Discover tab advising
Expand Down Expand Up @@ -340,25 +340,25 @@ class LinksMenuUI extends Component {
})
);
});
}
};

function error() {
console.log(
`viewExamples(): error finding type of field ${categorizationFieldName} in indices:`,
datafeedIndices
);
const { toasts } = this.props.kibana.services.notifications;
toasts.addDanger(
i18n.translate('xpack.ml.anomaliesTable.linksMenu.noMappingCouldBeFoundErrorMessage', {
defaultMessage:
'Unable to view examples of documents with mlcategory {categoryId} ' +
'as no mapping could be found for the categorization field {categorizationFieldName}',
values: {
categoryId,
categorizationFieldName,
},
function findFieldType(index) {
getFieldTypeFromMapping(index, categorizationFieldName)
.then(resp => {
if (resp !== '') {
createAndOpenUrl(index, resp);
} else {
i++;
if (i < datafeedIndices.length) {
findFieldType(datafeedIndices[i]);
} else {
error();
}
}
})
);
.catch(() => {
error();
});
}
};

Expand Down
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/ml/server/routes/apidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"CreateFilter",
"UpdateFilter",
"DeleteFilter",
"GetFiltersStats"
"GetFiltersStats",
"Indices",
"FieldCaps"
]
}
28 changes: 0 additions & 28 deletions x-pack/legacy/plugins/ml/server/routes/indices.js

This file was deleted.

49 changes: 49 additions & 0 deletions x-pack/legacy/plugins/ml/server/routes/indices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { schema } from '@kbn/config-schema';
import { wrapError } from '../client/error_wrapper';
import { licensePreRoutingFactory } from '../new_platform/licence_check_pre_routing_factory';
import { RouteInitialization } from '../new_platform/plugin';

/**
* Indices routes.
*/
export function indicesRoutes({ xpackMainPlugin, router }: RouteInitialization) {
/**
* @apiGroup Indices
*
* @api {post} /api/ml/indices/field_caps
* @apiName FieldCaps
* @apiDescription Retrieves the capabilities of fields among multiple indices.
*/
router.post(
{
path: '/api/ml/indices/field_caps',
validate: {
body: schema.object({
index: schema.maybe(schema.string()),
fields: schema.maybe(schema.arrayOf(schema.string())),
}),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
try {
const {
body: { index, fields: requestFields },
} = request;
const fields =
requestFields !== undefined && Array.isArray(requestFields)
? requestFields.join(',')
: '*';
const result = await context.ml!.mlClient.callAsCurrentUser('fieldCaps', { index, fields });
return response.ok({ body: result });
} catch (e) {
return response.customError(wrapError(e));
}
})
);
}