-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Changes default destination index field mapping and adds scripted_metric agg #40750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,5 @@ private void getPreview(Pivot pivot, ActionListener<List<Map<String, Object>>> l | |
| }, | ||
| listener::onFailure | ||
| )); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.index.mapper.NumberFieldMapper; | ||
| import org.elasticsearch.search.aggregations.AggregationBuilder; | ||
| import org.elasticsearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; | ||
| import org.elasticsearch.xpack.core.ClientHelper; | ||
| import org.elasticsearch.xpack.core.dataframe.transforms.pivot.PivotConfig; | ||
|
|
@@ -75,6 +76,8 @@ public static void deduceMappings(final Client client, | |
| ValuesSourceAggregationBuilder<?, ?> valueSourceAggregation = (ValuesSourceAggregationBuilder<?, ?>) agg; | ||
| aggregationSourceFieldNames.put(valueSourceAggregation.getName(), valueSourceAggregation.field()); | ||
| aggregationTypes.put(valueSourceAggregation.getName(), valueSourceAggregation.getType()); | ||
| } else if(agg instanceof ScriptedMetricAggregationBuilder) { | ||
| // do nothing | ||
|
||
| } else { | ||
| // execution should not reach this point | ||
| listener.onFailure(new RuntimeException("Unsupported aggregation type [" + agg.getType() + "]")); | ||
|
|
@@ -134,8 +137,7 @@ private static Map<String, String> resolveMappings(Map<String, String> aggregati | |
| if (destinationMapping != null) { | ||
|
||
| targetMapping.put(targetFieldName, destinationMapping); | ||
| } else { | ||
| logger.warn("Failed to deduce mapping for [" + targetFieldName + "], fall back to double."); | ||
| targetMapping.put(targetFieldName, "double"); | ||
| logger.warn("Failed to deduce mapping for [" + targetFieldName + "], fall back to dynamic mapping."); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 1st argument is the name known by aggregations, the 2nd the output type, which is either the concrete type or
nullif the source type should be used. Sonullis a magic variable and actually it should not be null forscripted_magic, but that's due to the lack of another magic.nullis a bad magic anyway and the types are well defined and limited. So I suggest to change this to:There should never be a type
sourceanddynamic, alternatively we could use_source,_dynamicto make the special meaning more visible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
resolveTargetMappingneeds to be changed, it should return the concrete source type ordynamic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice, for sure! Let me crank that out today. It would be better than implicitly having different behavior for
nullbetweenmaxandscripted_metric.