Skip to content

Commit 970f726

Browse files
authored
[ML] renaming inference processor field field_mappings to new name field_map (#53433)
This renames the `inference` processor configuration field `field_mappings` to `field_map`. `field_mappings` is now deprecated.
1 parent a8d89fd commit 970f726

File tree

11 files changed

+156
-30
lines changed

11 files changed

+156
-30
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ public void testGetTrainedModelsStats() throws Exception {
22652265
" \"target_field\": \"regression_value\",\n" +
22662266
" \"model_id\": \"" + modelIdPrefix + 0 + "\",\n" +
22672267
" \"inference_config\": {\"regression\": {}},\n" +
2268-
" \"field_mappings\": {\n" +
2268+
" \"field_map\": {\n" +
22692269
" \"col1\": \"col1\",\n" +
22702270
" \"col2\": \"col2\",\n" +
22712271
" \"col3\": \"col3\",\n" +

docs/reference/ingest/processors/inference.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ingested in the pipeline.
1414
| Name | Required | Default | Description
1515
| `model_id` | yes | - | (String) The ID of the model to load and infer against.
1616
| `target_field` | no | `ml.inference.<processor_tag>` | (String) Field added to incoming documents to contain results objects.
17-
| `field_mappings` | yes | - | (Object) Maps the document field names to the known field names of the model. This mapping takes precedence over any default mappings provided in the model configuration.
17+
| `field_map` | yes | - | (Object) Maps the document field names to the known field names of the model. This mapping takes precedence over any default mappings provided in the model configuration.
1818
| `inference_config` | yes | - | (Object) Contains the inference type and its options. There are two types: <<inference-processor-regression-opt,`regression`>> and <<inference-processor-classification-opt,`classification`>>.
1919
include::common-options.asciidoc[]
2020
|======
@@ -26,7 +26,7 @@ include::common-options.asciidoc[]
2626
"inference": {
2727
"model_id": "flight_delay_regression-1571767128603",
2828
"target_field": "FlightDelayMin_prediction_infer",
29-
"field_mappings": {},
29+
"field_map": {},
3030
"inference_config": { "regression": {} }
3131
}
3232
}

x-pack/plugin/ml/qa/ml-with-security/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ integTest.runner {
139139
'ml/inference_crud/Test put ensemble with empty models',
140140
'ml/inference_crud/Test put ensemble with tree where tree has out of bounds feature_names index',
141141
'ml/inference_crud/Test put model with empty input.field_names',
142+
'ml/inference_processor/Test create processor with missing mandatory fields',
143+
'ml/inference_processor/Test create and delete pipeline with inference processor',
144+
'ml/inference_processor/Test create processor with deprecated fields',
142145
'ml/inference_stats_crud/Test get stats given missing trained model',
143146
'ml/inference_stats_crud/Test get stats given expression without matches and allow_no_match is false',
144147
'ml/jobs_crud/Test cannot create job with existing categorizer state document',

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/InferenceIngestIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void testSimulate() throws IOException {
120120
" \"num_top_feature_importance_values\": 2" +
121121
" }},\n" +
122122
" \"model_id\": \"test_classification\",\n" +
123-
" \"field_mappings\": {\n" +
123+
" \"field_map\": {\n" +
124124
" \"col1\": \"col1\",\n" +
125125
" \"col2\": \"col2\",\n" +
126126
" \"col3\": \"col3\",\n" +
@@ -133,7 +133,7 @@ public void testSimulate() throws IOException {
133133
" \"target_field\": \"ml.regression\",\n" +
134134
" \"model_id\": \"test_regression\",\n" +
135135
" \"inference_config\": {\"regression\":{}},\n" +
136-
" \"field_mappings\": {\n" +
136+
" \"field_map\": {\n" +
137137
" \"col1\": \"col1\",\n" +
138138
" \"col2\": \"col2\",\n" +
139139
" \"col3\": \"col3\",\n" +
@@ -166,7 +166,7 @@ public void testSimulate() throws IOException {
166166
" \"inference\": {\n" +
167167
" \"model_id\": \"test_classification_missing\",\n" +
168168
" \"inference_config\": {\"classification\":{}},\n" +
169-
" \"field_mappings\": {\n" +
169+
" \"field_map\": {\n" +
170170
" \"col1\": \"col1\",\n" +
171171
" \"col2\": \"col2\",\n" +
172172
" \"col3\": \"col3\",\n" +
@@ -204,7 +204,7 @@ public void testSimulateWithDefaultMappedField() throws IOException {
204204
" \"num_top_feature_importance_values\": 2" +
205205
" }},\n" +
206206
" \"model_id\": \"test_classification\",\n" +
207-
" \"field_mappings\": {}\n" +
207+
" \"field_map\": {}\n" +
208208
" }\n" +
209209
" }\n"+
210210
" ]\n" +
@@ -233,7 +233,7 @@ public void testSimulateLangIdent() throws IOException {
233233
" \"inference\": {\n" +
234234
" \"inference_config\": {\"classification\":{}},\n" +
235235
" \"model_id\": \"lang_ident_model_1\",\n" +
236-
" \"field_mappings\": {}\n" +
236+
" \"field_map\": {}\n" +
237237
" }\n" +
238238
" }\n" +
239239
" ]\n" +
@@ -570,7 +570,7 @@ protected NamedXContentRegistry xContentRegistry() {
570570
" \"model_id\": \"test_classification\",\n" +
571571
" \"tag\": \"classification\",\n" +
572572
" \"inference_config\": {\"classification\": {}},\n" +
573-
" \"field_mappings\": {\n" +
573+
" \"field_map\": {\n" +
574574
" \"col1\": \"col1\",\n" +
575575
" \"col2\": \"col2\",\n" +
576576
" \"col3\": \"col3\",\n" +
@@ -586,7 +586,7 @@ protected NamedXContentRegistry xContentRegistry() {
586586
" \"model_id\": \"test_regression\",\n" +
587587
" \"tag\": \"regression\",\n" +
588588
" \"inference_config\": {\"regression\": {}},\n" +
589-
" \"field_mappings\": {\n" +
589+
" \"field_map\": {\n" +
590590
" \"col1\": \"col1\",\n" +
591591
" \"col2\": \"col2\",\n" +
592592
" \"col3\": \"col3\",\n" +

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessor.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.cluster.service.ClusterService;
1919
import org.elasticsearch.common.settings.Setting;
2020
import org.elasticsearch.common.settings.Settings;
21+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2122
import org.elasticsearch.ingest.AbstractProcessor;
2223
import org.elasticsearch.ingest.ConfigurationUtils;
2324
import org.elasticsearch.ingest.IngestDocument;
@@ -63,14 +64,15 @@ public class InferenceProcessor extends AbstractProcessor {
6364
public static final String INFERENCE_CONFIG = "inference_config";
6465
public static final String TARGET_FIELD = "target_field";
6566
public static final String FIELD_MAPPINGS = "field_mappings";
67+
public static final String FIELD_MAP = "field_map";
6668
private static final String DEFAULT_TARGET_FIELD = "ml.inference";
6769

6870
private final Client client;
6971
private final String modelId;
7072

7173
private final String targetField;
7274
private final InferenceConfig inferenceConfig;
73-
private final Map<String, String> fieldMapping;
75+
private final Map<String, String> fieldMap;
7476
private final InferenceAuditor auditor;
7577
private volatile boolean previouslyLicensed;
7678
private final AtomicBoolean shouldAudit = new AtomicBoolean(true);
@@ -81,14 +83,14 @@ public InferenceProcessor(Client client,
8183
String targetField,
8284
String modelId,
8385
InferenceConfig inferenceConfig,
84-
Map<String, String> fieldMapping) {
86+
Map<String, String> fieldMap) {
8587
super(tag);
8688
this.client = ExceptionsHelper.requireNonNull(client, "client");
8789
this.targetField = ExceptionsHelper.requireNonNull(targetField, TARGET_FIELD);
8890
this.auditor = ExceptionsHelper.requireNonNull(auditor, "auditor");
8991
this.modelId = ExceptionsHelper.requireNonNull(modelId, MODEL_ID);
9092
this.inferenceConfig = ExceptionsHelper.requireNonNull(inferenceConfig, INFERENCE_CONFIG);
91-
this.fieldMapping = ExceptionsHelper.requireNonNull(fieldMapping, FIELD_MAPPINGS);
93+
this.fieldMap = ExceptionsHelper.requireNonNull(fieldMap, FIELD_MAP);
9294
}
9395

9496
public String getModelId() {
@@ -126,7 +128,7 @@ void handleResponse(InternalInferModelAction.Response response,
126128

127129
InternalInferModelAction.Request buildRequest(IngestDocument ingestDocument) {
128130
Map<String, Object> fields = new HashMap<>(ingestDocument.getSourceAndMetadata());
129-
Model.mapFieldsIfNecessary(fields, fieldMapping);
131+
Model.mapFieldsIfNecessary(fields, fieldMap);
130132
return new InternalInferModelAction.Request(modelId, fields, inferenceConfig, previouslyLicensed);
131133
}
132134

@@ -235,7 +237,14 @@ public InferenceProcessor create(Map<String, Processor.Factory> processorFactori
235237
// If multiple inference processors are in the same pipeline, it is wise to tag them
236238
// The tag will keep default value entries from stepping on each other
237239
String targetField = ConfigurationUtils.readStringProperty(TYPE, tag, config, TARGET_FIELD, defaultTargetField);
238-
Map<String, String> fieldMapping = ConfigurationUtils.readOptionalMap(TYPE, tag, config, FIELD_MAPPINGS);
240+
Map<String, String> fieldMap = ConfigurationUtils.readOptionalMap(TYPE, tag, config, FIELD_MAP);
241+
if (fieldMap == null) {
242+
fieldMap = ConfigurationUtils.readOptionalMap(TYPE, tag, config, FIELD_MAPPINGS);
243+
//TODO Remove in 8.x
244+
if (fieldMap != null) {
245+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(FIELD_MAPPINGS, FIELD_MAP);
246+
}
247+
}
239248
InferenceConfig inferenceConfig = inferenceConfigFromMap(ConfigurationUtils.readMap(TYPE, tag, config, INFERENCE_CONFIG));
240249

241250
return new InferenceProcessor(client,
@@ -244,7 +253,7 @@ public InferenceProcessor create(Map<String, Processor.Factory> processorFactori
244253
targetField,
245254
modelId,
246255
inferenceConfig,
247-
fieldMapping);
256+
fieldMap);
248257
}
249258

250259
// Package private for testing

x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public void testMachineLearningCreateInferenceProcessorRestricted() throws Excep
484484
" \"target_field\": \"regression_value\",\n" +
485485
" \"model_id\": \"modelprocessorlicensetest\",\n" +
486486
" \"inference_config\": {\"regression\": {}},\n" +
487-
" \"field_mappings\": {}\n" +
487+
" \"field_map\": {}\n" +
488488
" }\n" +
489489
" }]}\n";
490490
// Creating a pipeline should work

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private static PipelineConfiguration newConfigurationWithInferenceProcessor(Stri
267267
new HashMap<String, Object>() {{
268268
put(InferenceProcessor.MODEL_ID, modelId);
269269
put("inference_config", Collections.singletonMap("regression", Collections.emptyMap()));
270-
put("field_mappings", Collections.emptyMap());
270+
put("field_map", Collections.emptyMap());
271271
put("target_field", randomAlphaOfLength(10));
272272
}}))))) {
273273
return new PipelineConfiguration("pipeline_with_model_" + modelId + num,

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessorFactoryTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testCreateProcessorWithInvalidInferenceConfig() {
131131
ingestService);
132132

133133
Map<String, Object> config = new HashMap<>() {{
134-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
134+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
135135
put(InferenceProcessor.MODEL_ID, "my_model");
136136
put(InferenceProcessor.TARGET_FIELD, "result");
137137
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap("unknown_type", Collections.emptyMap()));
@@ -143,7 +143,7 @@ public void testCreateProcessorWithInvalidInferenceConfig() {
143143
equalTo("unrecognized inference configuration type [unknown_type]. Supported types [classification, regression]"));
144144

145145
Map<String, Object> config2 = new HashMap<>() {{
146-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
146+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
147147
put(InferenceProcessor.MODEL_ID, "my_model");
148148
put(InferenceProcessor.TARGET_FIELD, "result");
149149
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap("regression", "boom"));
@@ -154,7 +154,7 @@ public void testCreateProcessorWithInvalidInferenceConfig() {
154154
equalTo("inference_config must be an object with one inference type mapped to an object."));
155155

156156
Map<String, Object> config3 = new HashMap<>() {{
157-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
157+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
158158
put(InferenceProcessor.MODEL_ID, "my_model");
159159
put(InferenceProcessor.TARGET_FIELD, "result");
160160
put(InferenceProcessor.INFERENCE_CONFIG, Collections.emptyMap());
@@ -173,7 +173,7 @@ public void testCreateProcessorWithTooOldMinNodeVersion() throws IOException {
173173
processorFactory.accept(builderClusterStateWithModelReferences(Version.V_7_5_0, "model1"));
174174

175175
Map<String, Object> regression = new HashMap<>() {{
176-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
176+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
177177
put(InferenceProcessor.MODEL_ID, "my_model");
178178
put(InferenceProcessor.TARGET_FIELD, "result");
179179
put(InferenceProcessor.INFERENCE_CONFIG,
@@ -191,7 +191,7 @@ public void testCreateProcessorWithTooOldMinNodeVersion() throws IOException {
191191
}
192192

193193
Map<String, Object> classification = new HashMap<>() {{
194-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
194+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
195195
put(InferenceProcessor.MODEL_ID, "my_model");
196196
put(InferenceProcessor.TARGET_FIELD, "result");
197197
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(ClassificationConfig.NAME.getPreferredName(),
@@ -216,7 +216,7 @@ public void testCreateProcessor() {
216216
ingestService);
217217

218218
Map<String, Object> regression = new HashMap<>() {{
219-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
219+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
220220
put(InferenceProcessor.MODEL_ID, "my_model");
221221
put(InferenceProcessor.TARGET_FIELD, "result");
222222
put(InferenceProcessor.INFERENCE_CONFIG,
@@ -230,7 +230,7 @@ public void testCreateProcessor() {
230230
}
231231

232232
Map<String, Object> classification = new HashMap<>() {{
233-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
233+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
234234
put(InferenceProcessor.MODEL_ID, "my_model");
235235
put(InferenceProcessor.TARGET_FIELD, "result");
236236
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(ClassificationConfig.NAME.getPreferredName(),
@@ -251,7 +251,7 @@ public void testCreateProcessorWithDuplicateFields() {
251251
ingestService);
252252

253253
Map<String, Object> regression = new HashMap<>() {{
254-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
254+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
255255
put(InferenceProcessor.MODEL_ID, "my_model");
256256
put(InferenceProcessor.TARGET_FIELD, "ml");
257257
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(RegressionConfig.NAME.getPreferredName(),
@@ -305,7 +305,7 @@ private static PipelineConfiguration newConfigurationWithInferenceProcessor(Stri
305305
put(InferenceProcessor.INFERENCE_CONFIG,
306306
Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap()));
307307
put(InferenceProcessor.TARGET_FIELD, "new_field");
308-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.singletonMap("source", "dest"));
308+
put(InferenceProcessor.FIELD_MAP, Collections.singletonMap("source", "dest"));
309309
}}))))) {
310310
return new PipelineConfiguration("pipeline_with_model_" + modelId, BytesReference.bytes(xContentBuilder), XContentType.JSON);
311311
}

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/inference_crud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ setup:
313313
"model_id" : "a-regression-model-0",
314314
"inference_config": {"regression": {}},
315315
"target_field": "regression_field",
316-
"field_mappings": {}
316+
"field_map": {}
317317
}
318318
}
319319
]

0 commit comments

Comments
 (0)