4545import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertSearchResponse ;
4646import static org .hamcrest .Matchers .equalTo ;
4747import static org .hamcrest .Matchers .greaterThan ;
48+ import static org .hamcrest .Matchers .hasEntry ;
4849import static org .hamcrest .Matchers .notNullValue ;
4950
5051@ ESIntegTestCase .SuiteScopeTestCase
@@ -59,7 +60,12 @@ public class AggregationProfilerIT extends ESIntegTestCase {
5960
6061 private static final String TOTAL_BUCKETS = "total_buckets" ;
6162 private static final String WRAPPED = "wrapped_in_multi_bucket_aggregator" ;
62- private static final Object DEFERRED = "deferred_aggregators" ;
63+ private static final String DEFERRED = "deferred_aggregators" ;
64+ private static final String COLLECTION_STRAT = "collection_strategy" ;
65+ private static final String RESULT_STRAT = "result_strategy" ;
66+ private static final String HAS_FILTER = "has_filter" ;
67+ private static final String SEGMENTS_WITH_SINGLE = "segments_with_single_valued_ords" ;
68+ private static final String SEGMENTS_WITH_MULTI = "segments_with_multi_valued_ords" ;
6369
6470 private static final String NUMBER_FIELD = "number" ;
6571 private static final String TAG_FIELD = "tag" ;
@@ -73,6 +79,7 @@ protected int numberOfShards() {
7379 @ Override
7480 protected void setupSuiteScopeCluster () throws Exception {
7581 assertAcked (client ().admin ().indices ().prepareCreate ("idx" )
82+ .setSettings (org .elasticsearch .common .collect .Map .of ("number_of_shards" , 1 , "number_of_replicas" , 0 ))
7683 .addMapping ("type" , STRING_FIELD , "type=keyword" , NUMBER_FIELD , "type=integer" , TAG_FIELD , "type=keyword" ).get ());
7784 List <IndexRequestBuilder > builders = new ArrayList <>();
7885
@@ -90,7 +97,7 @@ protected void setupSuiteScopeCluster() throws Exception {
9097 .endObject ()));
9198 }
9299
93- indexRandom (true , builders );
100+ indexRandom (true , false , builders );
94101 createIndex ("idx_unmapped" );
95102 }
96103
@@ -184,7 +191,7 @@ public void testMultiLevelProfile() {
184191 assertThat (termsBreakdown .get (COLLECT ), greaterThan (0L ));
185192 assertThat (termsBreakdown .get (BUILD_AGGREGATION ), greaterThan (0L ));
186193 assertThat (termsBreakdown .get (REDUCE ), equalTo (0L ));
187- assertThat (termsAggResult . getDebugInfo (), equalTo ( org . elasticsearch . common . collect . Map . of ( WRAPPED , true )) );
194+ assertRemapTermsDebugInfo (termsAggResult );
188195 assertThat (termsAggResult .getProfiledChildren ().size (), equalTo (1 ));
189196
190197 ProfileResult avgAggResult = termsAggResult .getProfiledChildren ().get (0 );
@@ -204,6 +211,18 @@ public void testMultiLevelProfile() {
204211 }
205212 }
206213
214+ private void assertRemapTermsDebugInfo (ProfileResult termsAggResult ) {
215+ assertThat (termsAggResult .getDebugInfo (), hasEntry (COLLECTION_STRAT , "remap" ));
216+ assertThat (termsAggResult .getDebugInfo (), hasEntry (RESULT_STRAT , "terms" ));
217+ assertThat (termsAggResult .getDebugInfo (), hasEntry (HAS_FILTER , false ));
218+ // TODO we only index single valued docs but the ordinals ends up with multi valued sometimes
219+ assertThat (
220+ termsAggResult .getDebugInfo ().toString (),
221+ (int ) termsAggResult .getDebugInfo ().get (SEGMENTS_WITH_SINGLE ) + (int ) termsAggResult .getDebugInfo ().get (SEGMENTS_WITH_MULTI ),
222+ greaterThan (0 )
223+ );
224+ }
225+
207226 public void testMultiLevelProfileBreadthFirst () {
208227 SearchResponse response = client ().prepareSearch ("idx" ).setProfile (true )
209228 .addAggregation (histogram ("histo" ).field (NUMBER_FIELD ).interval (1L ).subAggregation (terms ("terms" )
@@ -251,7 +270,7 @@ public void testMultiLevelProfileBreadthFirst() {
251270 assertThat (termsBreakdown .get (COLLECT ), greaterThan (0L ));
252271 assertThat (termsBreakdown .get (BUILD_AGGREGATION ), greaterThan (0L ));
253272 assertThat (termsBreakdown .get (REDUCE ), equalTo (0L ));
254- assertThat (termsAggResult . getDebugInfo (), equalTo ( org . elasticsearch . common . collect . Map . of ( WRAPPED , true )) );
273+ assertRemapTermsDebugInfo (termsAggResult );
255274 assertThat (termsAggResult .getProfiledChildren ().size (), equalTo (1 ));
256275
257276 ProfileResult avgAggResult = termsAggResult .getProfiledChildren ().get (0 );
@@ -378,7 +397,7 @@ public void testComplexProfile() {
378397 assertThat (tagsBreakdown .get (COLLECT ), greaterThan (0L ));
379398 assertThat (tagsBreakdown .get (BUILD_AGGREGATION ), greaterThan (0L ));
380399 assertThat (tagsBreakdown .get (REDUCE ), equalTo (0L ));
381- assertThat (tagsAggResult . getDebugInfo (), equalTo ( org . elasticsearch . common . collect . Map . of ( WRAPPED , true )) );
400+ assertRemapTermsDebugInfo (tagsAggResult );
382401 assertThat (tagsAggResult .getProfiledChildren ().size (), equalTo (2 ));
383402
384403 Map <String , ProfileResult > tagsAggResultSubAggregations = tagsAggResult .getProfiledChildren ().stream ()
@@ -423,7 +442,7 @@ public void testComplexProfile() {
423442 assertThat (stringsBreakdown .get (COLLECT ), greaterThan (0L ));
424443 assertThat (stringsBreakdown .get (BUILD_AGGREGATION ), greaterThan (0L ));
425444 assertThat (stringsBreakdown .get (REDUCE ), equalTo (0L ));
426- assertThat (stringsAggResult . getDebugInfo (), equalTo ( org . elasticsearch . common . collect . Map . of ( WRAPPED , true )) );
445+ assertRemapTermsDebugInfo (stringsAggResult );
427446 assertThat (stringsAggResult .getProfiledChildren ().size (), equalTo (3 ));
428447
429448 Map <String , ProfileResult > stringsAggResultSubAggregations = stringsAggResult .getProfiledChildren ().stream ()
@@ -469,7 +488,7 @@ public void testComplexProfile() {
469488 assertThat (tagsBreakdown .get (COLLECT ), greaterThan (0L ));
470489 assertThat (tagsBreakdown .get (BUILD_AGGREGATION ), greaterThan (0L ));
471490 assertThat (tagsBreakdown .get (REDUCE ), equalTo (0L ));
472- assertThat (tagsAggResult . getDebugInfo (), equalTo ( org . elasticsearch . common . collect . Map . of ( WRAPPED , true )) );
491+ assertRemapTermsDebugInfo (tagsAggResult );
473492 assertThat (tagsAggResult .getProfiledChildren ().size (), equalTo (2 ));
474493
475494 tagsAggResultSubAggregations = tagsAggResult .getProfiledChildren ().stream ()
0 commit comments