Skip to content

Commit 4e43ede

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

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
@@ -2297,7 +2297,7 @@ public void testGetTrainedModelsStats() throws Exception {
22972297
" \"target_field\": \"regression_value\",\n" +
22982298
" \"model_id\": \"" + modelIdPrefix + 0 + "\",\n" +
22992299
" \"inference_config\": {\"regression\": {}},\n" +
2300-
" \"field_mappings\": {\n" +
2300+
" \"field_map\": {\n" +
23012301
" \"col1\": \"col1\",\n" +
23022302
" \"col2\": \"col2\",\n" +
23032303
" \"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
@@ -564,7 +564,7 @@ public void testMachineLearningCreateInferenceProcessorRestricted() throws Excep
564564
" \"target_field\": \"regression_value\",\n" +
565565
" \"model_id\": \"modelprocessorlicensetest\",\n" +
566566
" \"inference_config\": {\"regression\": {}},\n" +
567-
" \"field_mappings\": {}\n" +
567+
" \"field_map\": {}\n" +
568568
" }\n" +
569569
" }]}\n";
570570
// 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
@@ -269,7 +269,7 @@ private static PipelineConfiguration newConfigurationWithInferenceProcessor(Stri
269269
new HashMap<String, Object>() {{
270270
put(InferenceProcessor.MODEL_ID, modelId);
271271
put("inference_config", Collections.singletonMap("regression", Collections.emptyMap()));
272-
put("field_mappings", Collections.emptyMap());
272+
put("field_map", Collections.emptyMap());
273273
put("target_field", randomAlphaOfLength(10));
274274
}}))))) {
275275
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
@@ -133,7 +133,7 @@ public void testCreateProcessorWithInvalidInferenceConfig() {
133133
ingestService);
134134

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

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

158158
Map<String, Object> config3 = new HashMap<String, Object>() {{
159-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
159+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
160160
put(InferenceProcessor.MODEL_ID, "my_model");
161161
put(InferenceProcessor.TARGET_FIELD, "result");
162162
put(InferenceProcessor.INFERENCE_CONFIG, Collections.emptyMap());
@@ -175,7 +175,7 @@ public void testCreateProcessorWithTooOldMinNodeVersion() throws IOException {
175175
processorFactory.accept(builderClusterStateWithModelReferences(Version.V_7_5_0, "model1"));
176176

177177
Map<String, Object> regression = new HashMap<String, Object>() {{
178-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
178+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
179179
put(InferenceProcessor.MODEL_ID, "my_model");
180180
put(InferenceProcessor.TARGET_FIELD, "result");
181181
put(InferenceProcessor.INFERENCE_CONFIG,
@@ -193,7 +193,7 @@ public void testCreateProcessorWithTooOldMinNodeVersion() throws IOException {
193193
}
194194

195195
Map<String, Object> classification = new HashMap<String, Object>() {{
196-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
196+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
197197
put(InferenceProcessor.MODEL_ID, "my_model");
198198
put(InferenceProcessor.TARGET_FIELD, "result");
199199
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(ClassificationConfig.NAME.getPreferredName(),
@@ -218,7 +218,7 @@ public void testCreateProcessor() {
218218
ingestService);
219219

220220
Map<String, Object> regression = new HashMap<String, Object>() {{
221-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
221+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
222222
put(InferenceProcessor.MODEL_ID, "my_model");
223223
put(InferenceProcessor.TARGET_FIELD, "result");
224224
put(InferenceProcessor.INFERENCE_CONFIG,
@@ -232,7 +232,7 @@ public void testCreateProcessor() {
232232
}
233233

234234
Map<String, Object> classification = new HashMap<String, Object>() {{
235-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
235+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
236236
put(InferenceProcessor.MODEL_ID, "my_model");
237237
put(InferenceProcessor.TARGET_FIELD, "result");
238238
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(ClassificationConfig.NAME.getPreferredName(),
@@ -253,7 +253,7 @@ public void testCreateProcessorWithDuplicateFields() {
253253
ingestService);
254254

255255
Map<String, Object> regression = new HashMap<String, Object>() {{
256-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.emptyMap());
256+
put(InferenceProcessor.FIELD_MAP, Collections.emptyMap());
257257
put(InferenceProcessor.MODEL_ID, "my_model");
258258
put(InferenceProcessor.TARGET_FIELD, "ml");
259259
put(InferenceProcessor.INFERENCE_CONFIG, Collections.singletonMap(RegressionConfig.NAME.getPreferredName(),
@@ -307,7 +307,7 @@ private static PipelineConfiguration newConfigurationWithInferenceProcessor(Stri
307307
put(InferenceProcessor.INFERENCE_CONFIG,
308308
Collections.singletonMap(RegressionConfig.NAME.getPreferredName(), Collections.emptyMap()));
309309
put(InferenceProcessor.TARGET_FIELD, "new_field");
310-
put(InferenceProcessor.FIELD_MAPPINGS, Collections.singletonMap("source", "dest"));
310+
put(InferenceProcessor.FIELD_MAP, Collections.singletonMap("source", "dest"));
311311
}}))))) {
312312
return new PipelineConfiguration("pipeline_with_model_" + modelId, BytesReference.bytes(xContentBuilder), XContentType.JSON);
313313
}

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)