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

[Backport 2.x] Omit field from mapping payload if it matches index field; Abort detector creation when mapping has failed #767

Merged
merged 3 commits into from
Nov 21, 2023
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
16 changes: 15 additions & 1 deletion public/pages/CreateDetector/containers/CreateDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NotificationsStart } from 'opensearch-dashboards/public';
import { getPlugins } from '../../../utils/helpers';
import { Detector, DetectorCreationStep } from '../../../../types';
import { DataStore } from '../../../store/DataStore';
import { errorNotificationToast } from '../../../utils/helpers';

interface CreateDetectorProps extends RouteComponentProps {
isEdit: boolean;
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
this.setState({ fieldMappings });
};

onCreateClick = () => {
onCreateClick = async () => {
const { creatingDetector, detector, fieldMappings } = this.state;
if (creatingDetector) {
return;
Expand All @@ -121,6 +122,19 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
fieldMappings
);

const fieldMappingRes = await fieldsMappingPromise;

if (!fieldMappingRes.ok) {
errorNotificationToast(
this.props.notifications,
'create',
'detector',
'Invalid field mappings.'
);
this.setState({ creatingDetector: false });
return;
}

const createDetectorPromise = this.props.services.detectorsService.createDetector(detector);

// set detector pending state, this will be used in detector details page
Expand Down
4 changes: 4 additions & 0 deletions public/services/FieldMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default class FieldMappingService {
properties: {},
};
fieldMappings.forEach((mapping) => {
if (mapping.ruleFieldName === mapping.indexFieldName) {
return;
}

alias_mappings.properties[mapping.ruleFieldName] = {
type: 'alias',
path: mapping.indexFieldName,
Expand Down
Loading