@@ -43,7 +43,8 @@ public void testMutateDocumentWithClassification() {
43
43
"classification_model" ,
44
44
new ClassificationConfig (0 ),
45
45
Collections .emptyMap (),
46
- "_ml_model.my_processor" );
46
+ "ml.my_processor" ,
47
+ true );
47
48
48
49
Map <String , Object > source = new HashMap <>();
49
50
Map <String , Object > ingestMetadata = new HashMap <>();
@@ -54,7 +55,7 @@ public void testMutateDocumentWithClassification() {
54
55
inferenceProcessor .mutateDocument (response , document );
55
56
56
57
assertThat (document .getFieldValue (targetField , String .class ), equalTo ("foo" ));
57
- assertThat (document .getFieldValue ("_ml_model " , Map .class ),
58
+ assertThat (document .getFieldValue ("ml " , Map .class ),
58
59
equalTo (Collections .singletonMap ("my_processor" , Collections .singletonMap ("model_id" , "classification_model" ))));
59
60
}
60
61
@@ -67,7 +68,8 @@ public void testMutateDocumentClassificationTopNClasses() {
67
68
"classification_model" ,
68
69
new ClassificationConfig (2 ),
69
70
Collections .emptyMap (),
70
- "_ml_model.my_processor" );
71
+ "ml.my_processor" ,
72
+ true );
71
73
72
74
Map <String , Object > source = new HashMap <>();
73
75
Map <String , Object > ingestMetadata = new HashMap <>();
@@ -83,7 +85,7 @@ public void testMutateDocumentClassificationTopNClasses() {
83
85
84
86
assertThat ((List <Map <?,?>>)document .getFieldValue (targetField , List .class ),
85
87
contains (classes .stream ().map (ClassificationInferenceResults .TopClassEntry ::asValueMap ).toArray (Map []::new )));
86
- assertThat (document .getFieldValue ("_ml_model " , Map .class ),
88
+ assertThat (document .getFieldValue ("ml " , Map .class ),
87
89
equalTo (Collections .singletonMap ("my_processor" , Collections .singletonMap ("model_id" , "classification_model" ))));
88
90
}
89
91
@@ -95,7 +97,8 @@ public void testMutateDocumentRegression() {
95
97
"regression_model" ,
96
98
new RegressionConfig (),
97
99
Collections .emptyMap (),
98
- "_ml_model.my_processor" );
100
+ "ml.my_processor" ,
101
+ true );
99
102
100
103
Map <String , Object > source = new HashMap <>();
101
104
Map <String , Object > ingestMetadata = new HashMap <>();
@@ -106,7 +109,7 @@ public void testMutateDocumentRegression() {
106
109
inferenceProcessor .mutateDocument (response , document );
107
110
108
111
assertThat (document .getFieldValue (targetField , Double .class ), equalTo (0.7 ));
109
- assertThat (document .getFieldValue ("_ml_model " , Map .class ),
112
+ assertThat (document .getFieldValue ("ml " , Map .class ),
110
113
equalTo (Collections .singletonMap ("my_processor" , Collections .singletonMap ("model_id" , "regression_model" ))));
111
114
}
112
115
@@ -118,7 +121,8 @@ public void testMutateDocumentNoModelMetaData() {
118
121
"regression_model" ,
119
122
new RegressionConfig (),
120
123
Collections .emptyMap (),
121
- null );
124
+ "ml.my_processor" ,
125
+ false );
122
126
123
127
Map <String , Object > source = new HashMap <>();
124
128
Map <String , Object > ingestMetadata = new HashMap <>();
@@ -129,20 +133,54 @@ public void testMutateDocumentNoModelMetaData() {
129
133
inferenceProcessor .mutateDocument (response , document );
130
134
131
135
assertThat (document .getFieldValue (targetField , Double .class ), equalTo (0.7 ));
132
- assertThat (document .hasField ("_ml_model" ), is (false ));
136
+ assertThat (document .hasField ("ml" ), is (false ));
137
+ }
138
+
139
+ public void testMutateDocumentModelMetaDataExistingField () {
140
+ String targetField = "regression_value" ;
141
+ InferenceProcessor inferenceProcessor = new InferenceProcessor (client ,
142
+ "my_processor" ,
143
+ targetField ,
144
+ "regression_model" ,
145
+ new RegressionConfig (),
146
+ Collections .emptyMap (),
147
+ "ml.my_processor" ,
148
+ true );
149
+
150
+ //cannot use singleton map as attempting to mutate later
151
+ Map <String , Object > ml = new HashMap <>(){{
152
+ put ("regression_prediction" , 0.55 );
153
+ }};
154
+ Map <String , Object > source = new HashMap <>(){{
155
+ put ("ml" , ml );
156
+ }};
157
+ Map <String , Object > ingestMetadata = new HashMap <>();
158
+ IngestDocument document = new IngestDocument (source , ingestMetadata );
159
+
160
+ InferModelAction .Response response = new InferModelAction .Response (
161
+ Collections .singletonList (new RegressionInferenceResults (0.7 )));
162
+ inferenceProcessor .mutateDocument (response , document );
163
+
164
+ assertThat (document .getFieldValue (targetField , Double .class ), equalTo (0.7 ));
165
+ assertThat (document .getFieldValue ("ml" , Map .class ),
166
+ equalTo (new HashMap <>(){{
167
+ put ("my_processor" , Collections .singletonMap ("model_id" , "regression_model" ));
168
+ put ("regression_prediction" , 0.55 );
169
+ }}));
133
170
}
134
171
135
172
public void testGenerateRequestWithEmptyMapping () {
136
173
String modelId = "model" ;
137
174
Integer topNClasses = randomBoolean () ? null : randomIntBetween (1 , 10 );
138
175
139
176
InferenceProcessor processor = new InferenceProcessor (client ,
140
- "my_processor" ,
141
- "my_field" ,
142
- modelId ,
143
- new ClassificationConfig (topNClasses ),
144
- Collections .emptyMap (),
145
- null );
177
+ "my_processor" ,
178
+ "my_field" ,
179
+ modelId ,
180
+ new ClassificationConfig (topNClasses ),
181
+ Collections .emptyMap (),
182
+ "ml.my_processor" ,
183
+ false );
146
184
147
185
Map <String , Object > source = new HashMap <>(){{
148
186
put ("value1" , 1 );
@@ -171,7 +209,8 @@ public void testGenerateWithMapping() {
171
209
modelId ,
172
210
new ClassificationConfig (topNClasses ),
173
211
fieldMapping ,
174
- null );
212
+ "ml.my_processor" ,
213
+ false );
175
214
176
215
Map <String , Object > source = new HashMap <>(3 ){{
177
216
put ("value1" , 1 );
0 commit comments