|
13 | 13 | import org.elasticsearch.common.xcontent.ObjectParser; |
14 | 14 | import org.elasticsearch.common.xcontent.XContentBuilder; |
15 | 15 | import org.elasticsearch.common.xcontent.XContentParser; |
| 16 | +import org.elasticsearch.index.mapper.KeywordFieldMapper; |
| 17 | +import org.elasticsearch.index.mapper.NumberFieldMapper; |
| 18 | +import org.elasticsearch.index.mapper.ObjectMapper; |
16 | 19 | import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfig; |
17 | 20 | import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; |
18 | 21 |
|
@@ -56,6 +59,20 @@ public static OutlierDetection fromXContent(XContentParser parser, boolean ignor |
56 | 59 |
|
57 | 60 | private static final List<String> PROGRESS_PHASES = Collections.singletonList("computing_outliers"); |
58 | 61 |
|
| 62 | + static final Map<String, Object> FEATURE_INFLUENCE_MAPPING; |
| 63 | + static { |
| 64 | + Map<String, Object> properties = new HashMap<>(); |
| 65 | + properties.put("feature_name", Collections.singletonMap("type", KeywordFieldMapper.CONTENT_TYPE)); |
| 66 | + properties.put("influence", Collections.singletonMap("type", NumberFieldMapper.NumberType.DOUBLE.typeName())); |
| 67 | + |
| 68 | + Map<String, Object> mapping = new HashMap<>(); |
| 69 | + mapping.put("dynamic", false); |
| 70 | + mapping.put("type", ObjectMapper.NESTED_CONTENT_TYPE); |
| 71 | + mapping.put("properties", properties); |
| 72 | + |
| 73 | + FEATURE_INFLUENCE_MAPPING = Collections.unmodifiableMap(mapping); |
| 74 | + } |
| 75 | + |
59 | 76 | /** |
60 | 77 | * The number of neighbors. Leave unspecified for dynamic detection. |
61 | 78 | */ |
@@ -229,7 +246,11 @@ public List<FieldCardinalityConstraint> getFieldCardinalityConstraints() { |
229 | 246 |
|
230 | 247 | @Override |
231 | 248 | public Map<String, Object> getExplicitlyMappedFields(Map<String, Object> mappingsProperties, String resultsFieldName) { |
232 | | - return Collections.emptyMap(); |
| 249 | + Map<String, Object> additionalProperties = new HashMap<>(); |
| 250 | + additionalProperties.put(resultsFieldName + ".outlier_score", |
| 251 | + Collections.singletonMap("type", NumberFieldMapper.NumberType.DOUBLE.typeName())); |
| 252 | + additionalProperties.put(resultsFieldName + ".feature_influence", FEATURE_INFLUENCE_MAPPING); |
| 253 | + return additionalProperties; |
233 | 254 | } |
234 | 255 |
|
235 | 256 | @Override |
|
0 commit comments