|
34 | 34 |
|
35 | 35 | import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
36 | 36 |
|
| 37 | +import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; |
37 | 38 | import org.opensearch.action.index.IndexRequestBuilder;
|
38 | 39 | import org.opensearch.action.search.SearchResponse;
|
39 | 40 | import org.opensearch.common.settings.Settings;
|
|
59 | 60 | import static java.util.Collections.emptyMap;
|
60 | 61 | import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
|
61 | 62 | import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
|
| 63 | +import static org.opensearch.search.SearchService.CARDINALITY_AGGREGATION_PRUNING_THRESHOLD; |
62 | 64 | import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
|
63 | 65 | import static org.opensearch.search.aggregations.AggregationBuilders.cardinality;
|
64 | 66 | import static org.opensearch.search.aggregations.AggregationBuilders.global;
|
@@ -255,6 +257,36 @@ public void testSingleValuedString() throws Exception {
|
255 | 257 | assertCount(count, numDocs);
|
256 | 258 | }
|
257 | 259 |
|
| 260 | + public void testDisableDynamicPruning() throws Exception { |
| 261 | + SearchResponse response = client().prepareSearch("idx") |
| 262 | + .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value")) |
| 263 | + .get(); |
| 264 | + assertSearchResponse(response); |
| 265 | + |
| 266 | + Cardinality count1 = response.getAggregations().get("cardinality"); |
| 267 | + |
| 268 | + final ClusterUpdateSettingsResponse updateSettingResponse = client().admin() |
| 269 | + .cluster() |
| 270 | + .prepareUpdateSettings() |
| 271 | + .setTransientSettings(Settings.builder().put(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey(), 0)) |
| 272 | + .get(); |
| 273 | + assertEquals(updateSettingResponse.getTransientSettings().get(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey()), "0"); |
| 274 | + |
| 275 | + response = client().prepareSearch("idx") |
| 276 | + .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value")) |
| 277 | + .get(); |
| 278 | + assertSearchResponse(response); |
| 279 | + Cardinality count2 = response.getAggregations().get("cardinality"); |
| 280 | + |
| 281 | + assertEquals(count1, count2); |
| 282 | + |
| 283 | + client().admin() |
| 284 | + .cluster() |
| 285 | + .prepareUpdateSettings() |
| 286 | + .setTransientSettings(Settings.builder().putNull(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey())) |
| 287 | + .get(); |
| 288 | + } |
| 289 | + |
258 | 290 | public void testSingleValuedNumeric() throws Exception {
|
259 | 291 | SearchResponse response = client().prepareSearch("idx")
|
260 | 292 | .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
|
|
0 commit comments