|
31 | 31 | import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
|
32 | 32 | import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig;
|
33 | 33 | import org.elasticsearch.xpack.core.dataframe.transforms.SourceConfig;
|
| 34 | +import org.elasticsearch.xpack.dataframe.transforms.pivot.AggregationResultUtils; |
34 | 35 | import org.elasticsearch.xpack.dataframe.transforms.pivot.Pivot;
|
35 | 36 |
|
36 | 37 | import java.util.List;
|
@@ -102,14 +103,21 @@ private void getPreview(Pivot pivot, SourceConfig source, ActionListener<List<Ma
|
102 | 103 | pivot.buildSearchRequest(source, null, NUMBER_OF_PREVIEW_BUCKETS),
|
103 | 104 | ActionListener.wrap(
|
104 | 105 | r -> {
|
105 |
| - final CompositeAggregation agg = r.getAggregations().get(COMPOSITE_AGGREGATION_NAME); |
106 |
| - DataFrameIndexerTransformStats stats = DataFrameIndexerTransformStats.withDefaultTransformId(); |
107 |
| - // remove all internal fields |
108 |
| - List<Map<String, Object>> results = pivot.extractResults(agg, deducedMappings, stats) |
109 |
| - .peek(record -> { |
110 |
| - record.keySet().removeIf(k -> k.startsWith("_")); |
111 |
| - }).collect(Collectors.toList()); |
112 |
| - listener.onResponse(results); |
| 106 | + |
| 107 | + try { |
| 108 | + final CompositeAggregation agg = r.getAggregations().get(COMPOSITE_AGGREGATION_NAME); |
| 109 | + DataFrameIndexerTransformStats stats = DataFrameIndexerTransformStats.withDefaultTransformId(); |
| 110 | + // remove all internal fields |
| 111 | + List<Map<String, Object>> results = pivot.extractResults(agg, deducedMappings, stats) |
| 112 | + .peek(record -> { |
| 113 | + record.keySet().removeIf(k -> k.startsWith("_")); |
| 114 | + }).collect(Collectors.toList()); |
| 115 | + |
| 116 | + listener.onResponse(results); |
| 117 | + } catch (AggregationResultUtils.AggregationExtractionException extractionException) { |
| 118 | + listener.onFailure( |
| 119 | + new ElasticsearchStatusException(extractionException.getMessage(), RestStatus.BAD_REQUEST)); |
| 120 | + } |
113 | 121 | },
|
114 | 122 | listener::onFailure
|
115 | 123 | ));
|
|
0 commit comments