[Ml Data Frame] Return bad_request on preview when config is invalid (#42447)
This commit is contained in:
parent
c21745c8ab
commit
aea600fe7d
|
@ -31,6 +31,7 @@ import org.elasticsearch.xpack.core.dataframe.action.PreviewDataFrameTransformAc
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig;
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.SourceConfig;
|
import org.elasticsearch.xpack.core.dataframe.transforms.SourceConfig;
|
||||||
|
import org.elasticsearch.xpack.dataframe.transforms.pivot.AggregationResultUtils;
|
||||||
import org.elasticsearch.xpack.dataframe.transforms.pivot.Pivot;
|
import org.elasticsearch.xpack.dataframe.transforms.pivot.Pivot;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -102,6 +103,8 @@ public class TransportPreviewDataFrameTransformAction extends
|
||||||
pivot.buildSearchRequest(source, null, NUMBER_OF_PREVIEW_BUCKETS),
|
pivot.buildSearchRequest(source, null, NUMBER_OF_PREVIEW_BUCKETS),
|
||||||
ActionListener.wrap(
|
ActionListener.wrap(
|
||||||
r -> {
|
r -> {
|
||||||
|
|
||||||
|
try {
|
||||||
final CompositeAggregation agg = r.getAggregations().get(COMPOSITE_AGGREGATION_NAME);
|
final CompositeAggregation agg = r.getAggregations().get(COMPOSITE_AGGREGATION_NAME);
|
||||||
DataFrameIndexerTransformStats stats = DataFrameIndexerTransformStats.withDefaultTransformId();
|
DataFrameIndexerTransformStats stats = DataFrameIndexerTransformStats.withDefaultTransformId();
|
||||||
// remove all internal fields
|
// remove all internal fields
|
||||||
|
@ -109,7 +112,12 @@ public class TransportPreviewDataFrameTransformAction extends
|
||||||
.peek(record -> {
|
.peek(record -> {
|
||||||
record.keySet().removeIf(k -> k.startsWith("_"));
|
record.keySet().removeIf(k -> k.startsWith("_"));
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
listener.onResponse(results);
|
listener.onResponse(results);
|
||||||
|
} catch (AggregationResultUtils.AggregationExtractionException extractionException) {
|
||||||
|
listener.onFailure(
|
||||||
|
new ElasticsearchStatusException(extractionException.getMessage(), RestStatus.BAD_REQUEST));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
listener::onFailure
|
listener::onFailure
|
||||||
));
|
));
|
||||||
|
|
|
@ -127,3 +127,38 @@ setup:
|
||||||
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
|
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test preview returns bad request with invalid agg":
|
||||||
|
- do:
|
||||||
|
catch: bad_request
|
||||||
|
data_frame.preview_data_frame_transform:
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"source": { "index": "airline-data" },
|
||||||
|
"pivot": {
|
||||||
|
"group_by": {
|
||||||
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-DD HH"}}},
|
||||||
|
"aggs": {
|
||||||
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
|
"time.min": {"min": {"field": "time"}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- do:
|
||||||
|
catch: /mixed object types of nested and non-nested fields \[time.min\]/
|
||||||
|
data_frame.preview_data_frame_transform:
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"source": { "index": "airline-data" },
|
||||||
|
"pivot": {
|
||||||
|
"group_by": {
|
||||||
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-DD HH"}}},
|
||||||
|
"aggs": {
|
||||||
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
|
"time.min": {"min": {"field": "time"}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue