Have createPipeline pass along fieldMappings (#154951)

## Summary

previously createPipeline wasn't passing along fieldMappings, which was
leading to errors like:

<img width="968" alt="screenshot"
src="https://user-images.githubusercontent.com/5288246/231869339-82756b7a-a899-4e91-b056-b20512358c21.png">


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
Sean Story 2023-04-17 08:43:46 -05:00 committed by GitHub
parent f3e5759a73
commit d213107c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 7 deletions

View file

@ -7,6 +7,8 @@
import { IngestInferenceConfig, IngestPipeline } from '@elastic/elasticsearch/lib/api/types';
import { FieldMapping } from '../ml_inference_pipeline';
export interface InferencePipeline {
modelId: string | undefined;
modelState: TrainedModelState;
@ -81,6 +83,7 @@ export interface CreateMlInferencePipelineParameters {
}
export interface CreateMLInferencePipelineDefinition {
field_mappings: FieldMapping[];
pipeline_definition: MlInferencePipeline;
pipeline_name: string;
}

View file

@ -4,6 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FieldMapping } from '../../../../../common/ml_inference_pipeline';
import {
CreateMlInferencePipelineParameters,
CreateMLInferencePipelineDefinition,
@ -23,9 +25,10 @@ interface CreateMlInferencePipelineApiLogicArgsWithPipelineParameters {
}
interface CreateMlInferencePipelineApiLogicArgsWithPipelineDefinition {
fieldMappings: FieldMapping[];
indexName: string;
pipelineName: string;
pipelineDefinition: MlInferencePipeline;
pipelineName: string;
}
export type CreateMlInferencePipelineApiLogicArgs =
@ -64,14 +67,15 @@ export const createMlInferencePipeline = async (
destination_field: args.destinationField,
inference_config: args.inferenceConfig,
model_id: args.modelId,
pipeline_name: args.pipelineName,
pipeline_definition: undefined,
pipeline_name: args.pipelineName,
source_field: args.sourceField,
};
} else if (isArgsWithPipelineDefinition(args)) {
params = {
pipeline_name: args.pipelineName,
field_mappings: args.fieldMappings,
pipeline_definition: args.pipelineDefinition,
pipeline_name: args.pipelineName,
};
}
return await HttpLogic.values.http.post<CreateMlInferencePipelineResponse>(route, {

View file

@ -531,10 +531,16 @@ describe('MlInferenceLogic', () => {
MLModelsApiLogic.actions.apiSuccess([textExpansionModel]);
MLInferenceLogic.actions.setInferencePipelineConfiguration({
destinationField: 'my-dest-field',
destinationField: mockModelConfiguration.configuration.destinationField,
fieldMappings: [
{
sourceField: 'source',
targetField: 'ml.inference.dest',
},
],
modelID: textExpansionModel.model_id,
pipelineName: mockModelConfiguration.configuration.pipelineName,
sourceField: 'my-field',
sourceField: mockModelConfiguration.configuration.sourceField,
});
MLInferenceLogic.actions.createPipeline();
@ -542,6 +548,12 @@ describe('MlInferenceLogic', () => {
indexName: mockModelConfiguration.indexName,
pipelineName: mockModelConfiguration.configuration.pipelineName,
pipelineDefinition: expect.any(Object), // Generation logic is tested elsewhere
fieldMappings: [
{
sourceField: 'source',
targetField: 'ml.inference.dest',
},
],
});
});
});

View file

@ -257,11 +257,12 @@ export const MLInferenceLogic = kea<
mlInferencePipeline, // Full pipeline definition
} = values;
actions.makeCreatePipelineRequest(
isTextExpansionModelSelected && mlInferencePipeline
isTextExpansionModelSelected && mlInferencePipeline && configuration.fieldMappings
? {
indexName,
pipelineName: configuration.pipelineName,
fieldMappings: configuration.fieldMappings,
pipelineDefinition: mlInferencePipeline,
pipelineName: configuration.pipelineName,
}
: {
destinationField: