Search in sources :

Example 1 with ProfileShardResult

use of org.elasticsearch.search.profile.ProfileShardResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testSimpleProfile.

public void testSimpleProfile() {
    SearchResponse response = client().prepareSearch("idx").setProfile(true).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L)).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(getNumShards("idx").numPrimaries));
    for (ProfileShardResult profileShardResult : profileResults.values()) {
        assertThat(profileShardResult, notNullValue());
        AggregationProfileShardResult aggProfileResults = profileShardResult.getAggregationProfileResults();
        assertThat(aggProfileResults, notNullValue());
        List<ProfileResult> aggProfileResultsList = aggProfileResults.getProfileResults();
        assertThat(aggProfileResultsList, notNullValue());
        assertThat(aggProfileResultsList.size(), equalTo(1));
        ProfileResult histoAggResult = aggProfileResultsList.get(0);
        assertThat(histoAggResult, notNullValue());
        assertThat(histoAggResult.getQueryName(), equalTo("org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator"));
        assertThat(histoAggResult.getLuceneDescription(), equalTo("histo"));
        assertThat(histoAggResult.getProfiledChildren().size(), equalTo(0));
        assertThat(histoAggResult.getTime(), greaterThan(0L));
        Map<String, Long> breakdown = histoAggResult.getTimeBreakdown();
        assertThat(breakdown, notNullValue());
        assertThat(breakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(breakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(breakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
    }
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) ProfileResult(org.elasticsearch.search.profile.ProfileResult) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 2 with ProfileShardResult

use of org.elasticsearch.search.profile.ProfileShardResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testMultiLevelProfileBreadthFirst.

public void testMultiLevelProfileBreadthFirst() {
    SearchResponse response = client().prepareSearch("idx").setProfile(true).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L).subAggregation(terms("terms").collectMode(SubAggCollectionMode.BREADTH_FIRST).field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)))).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(getNumShards("idx").numPrimaries));
    for (ProfileShardResult profileShardResult : profileResults.values()) {
        assertThat(profileShardResult, notNullValue());
        AggregationProfileShardResult aggProfileResults = profileShardResult.getAggregationProfileResults();
        assertThat(aggProfileResults, notNullValue());
        List<ProfileResult> aggProfileResultsList = aggProfileResults.getProfileResults();
        assertThat(aggProfileResultsList, notNullValue());
        assertThat(aggProfileResultsList.size(), equalTo(1));
        ProfileResult histoAggResult = aggProfileResultsList.get(0);
        assertThat(histoAggResult, notNullValue());
        assertThat(histoAggResult.getQueryName(), equalTo("org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator"));
        assertThat(histoAggResult.getLuceneDescription(), equalTo("histo"));
        assertThat(histoAggResult.getTime(), greaterThan(0L));
        Map<String, Long> histoBreakdown = histoAggResult.getTimeBreakdown();
        assertThat(histoBreakdown, notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(histoAggResult.getProfiledChildren().size(), equalTo(1));
        ProfileResult termsAggResult = histoAggResult.getProfiledChildren().get(0);
        assertThat(termsAggResult, notNullValue());
        assertThat(termsAggResult.getQueryName(), equalTo(GlobalOrdinalsStringTermsAggregator.WithHash.class.getName()));
        assertThat(termsAggResult.getLuceneDescription(), equalTo("terms"));
        assertThat(termsAggResult.getTime(), greaterThan(0L));
        Map<String, Long> termsBreakdown = termsAggResult.getTimeBreakdown();
        assertThat(termsBreakdown, notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(termsBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(termsBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(termsAggResult.getProfiledChildren().size(), equalTo(1));
        ProfileResult avgAggResult = termsAggResult.getProfiledChildren().get(0);
        assertThat(avgAggResult, notNullValue());
        assertThat(avgAggResult.getQueryName(), equalTo(AvgAggregator.class.getName()));
        assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
        assertThat(avgAggResult.getTime(), greaterThan(0L));
        Map<String, Long> avgBreakdown = termsAggResult.getTimeBreakdown();
        assertThat(avgBreakdown, notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
    }
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) ProfileResult(org.elasticsearch.search.profile.ProfileResult) GlobalOrdinalsStringTermsAggregator(org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 3 with ProfileShardResult

use of org.elasticsearch.search.profile.ProfileShardResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testNoProfile.

public void testNoProfile() {
    SearchResponse response = client().prepareSearch("idx").setProfile(false).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L).subAggregation(terms("tags").field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD))).subAggregation(terms("strings").field(STRING_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD)).subAggregation(terms("tags").field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD))))).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(0));
}
Also used : SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 4 with ProfileShardResult

use of org.elasticsearch.search.profile.ProfileShardResult in project elasticsearch by elastic.

the class AggregationProfilerIT method testComplexProfile.

public void testComplexProfile() {
    SearchResponse response = client().prepareSearch("idx").setProfile(true).addAggregation(histogram("histo").field(NUMBER_FIELD).interval(1L).subAggregation(terms("tags").field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD))).subAggregation(terms("strings").field(STRING_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD)).subAggregation(terms("tags").field(TAG_FIELD).subAggregation(avg("avg").field(NUMBER_FIELD)).subAggregation(max("max").field(NUMBER_FIELD))))).get();
    assertSearchResponse(response);
    Map<String, ProfileShardResult> profileResults = response.getProfileResults();
    assertThat(profileResults, notNullValue());
    assertThat(profileResults.size(), equalTo(getNumShards("idx").numPrimaries));
    for (ProfileShardResult profileShardResult : profileResults.values()) {
        assertThat(profileShardResult, notNullValue());
        AggregationProfileShardResult aggProfileResults = profileShardResult.getAggregationProfileResults();
        assertThat(aggProfileResults, notNullValue());
        List<ProfileResult> aggProfileResultsList = aggProfileResults.getProfileResults();
        assertThat(aggProfileResultsList, notNullValue());
        assertThat(aggProfileResultsList.size(), equalTo(1));
        ProfileResult histoAggResult = aggProfileResultsList.get(0);
        assertThat(histoAggResult, notNullValue());
        assertThat(histoAggResult.getQueryName(), equalTo("org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator"));
        assertThat(histoAggResult.getLuceneDescription(), equalTo("histo"));
        assertThat(histoAggResult.getTime(), greaterThan(0L));
        Map<String, Long> histoBreakdown = histoAggResult.getTimeBreakdown();
        assertThat(histoBreakdown, notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(histoBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(histoAggResult.getProfiledChildren().size(), equalTo(2));
        ProfileResult tagsAggResult = histoAggResult.getProfiledChildren().get(0);
        assertThat(tagsAggResult, notNullValue());
        assertThat(tagsAggResult.getQueryName(), equalTo(GlobalOrdinalsStringTermsAggregator.WithHash.class.getName()));
        assertThat(tagsAggResult.getLuceneDescription(), equalTo("tags"));
        assertThat(tagsAggResult.getTime(), greaterThan(0L));
        Map<String, Long> tagsBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(tagsBreakdown, notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(tagsAggResult.getProfiledChildren().size(), equalTo(2));
        ProfileResult avgAggResult = tagsAggResult.getProfiledChildren().get(0);
        assertThat(avgAggResult, notNullValue());
        assertThat(avgAggResult.getQueryName(), equalTo(AvgAggregator.class.getName()));
        assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
        assertThat(avgAggResult.getTime(), greaterThan(0L));
        Map<String, Long> avgBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(avgBreakdown, notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
        ProfileResult maxAggResult = tagsAggResult.getProfiledChildren().get(1);
        assertThat(maxAggResult, notNullValue());
        assertThat(maxAggResult.getQueryName(), equalTo(MaxAggregator.class.getName()));
        assertThat(maxAggResult.getLuceneDescription(), equalTo("max"));
        assertThat(maxAggResult.getTime(), greaterThan(0L));
        Map<String, Long> maxBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(maxBreakdown, notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
        ProfileResult stringsAggResult = histoAggResult.getProfiledChildren().get(1);
        assertThat(stringsAggResult, notNullValue());
        assertThat(stringsAggResult.getQueryName(), equalTo(GlobalOrdinalsStringTermsAggregator.WithHash.class.getName()));
        assertThat(stringsAggResult.getLuceneDescription(), equalTo("strings"));
        assertThat(stringsAggResult.getTime(), greaterThan(0L));
        Map<String, Long> stringsBreakdown = stringsAggResult.getTimeBreakdown();
        assertThat(stringsBreakdown, notNullValue());
        assertThat(stringsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(stringsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(stringsBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(stringsBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(stringsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(stringsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(stringsBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(stringsBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(stringsAggResult.getProfiledChildren().size(), equalTo(3));
        avgAggResult = stringsAggResult.getProfiledChildren().get(0);
        assertThat(avgAggResult, notNullValue());
        assertThat(avgAggResult.getQueryName(), equalTo(AvgAggregator.class.getName()));
        assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
        assertThat(avgAggResult.getTime(), greaterThan(0L));
        avgBreakdown = stringsAggResult.getTimeBreakdown();
        assertThat(avgBreakdown, notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
        maxAggResult = stringsAggResult.getProfiledChildren().get(1);
        assertThat(maxAggResult, notNullValue());
        assertThat(maxAggResult.getQueryName(), equalTo(MaxAggregator.class.getName()));
        assertThat(maxAggResult.getLuceneDescription(), equalTo("max"));
        assertThat(maxAggResult.getTime(), greaterThan(0L));
        maxBreakdown = stringsAggResult.getTimeBreakdown();
        assertThat(maxBreakdown, notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
        tagsAggResult = stringsAggResult.getProfiledChildren().get(2);
        assertThat(tagsAggResult, notNullValue());
        assertThat(tagsAggResult.getQueryName(), equalTo(GlobalOrdinalsStringTermsAggregator.WithHash.class.getName()));
        assertThat(tagsAggResult.getLuceneDescription(), equalTo("tags"));
        assertThat(tagsAggResult.getTime(), greaterThan(0L));
        tagsBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(tagsBreakdown, notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(tagsBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(tagsBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(tagsAggResult.getProfiledChildren().size(), equalTo(2));
        avgAggResult = tagsAggResult.getProfiledChildren().get(0);
        assertThat(avgAggResult, notNullValue());
        assertThat(avgAggResult.getQueryName(), equalTo(AvgAggregator.class.getName()));
        assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
        assertThat(avgAggResult.getTime(), greaterThan(0L));
        avgBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(avgBreakdown, notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(avgBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
        maxAggResult = tagsAggResult.getProfiledChildren().get(1);
        assertThat(maxAggResult, notNullValue());
        assertThat(maxAggResult.getQueryName(), equalTo(MaxAggregator.class.getName()));
        assertThat(maxAggResult.getLuceneDescription(), equalTo("max"));
        assertThat(maxAggResult.getTime(), greaterThan(0L));
        maxBreakdown = tagsAggResult.getTimeBreakdown();
        assertThat(maxBreakdown, notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.INITIALIZE.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.COLLECT.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.BUILD_AGGREGATION.toString()), greaterThan(0L));
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), notNullValue());
        assertThat(maxBreakdown.get(AggregationTimingType.REDUCE.toString()), equalTo(0L));
        assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
    }
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) ProfileResult(org.elasticsearch.search.profile.ProfileResult) GlobalOrdinalsStringTermsAggregator(org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 5 with ProfileShardResult

use of org.elasticsearch.search.profile.ProfileShardResult in project elasticsearch by elastic.

the class QueryProfilerIT method testCollapsingBool.

/**
     * Tests a series of three nested boolean queries with a single "leaf" match query.
     * The rewrite process will "collapse" this down to a single bool, so this tests to make sure
     * nothing catastrophic happens during that fairly substantial rewrite
     */
public void testCollapsingBool() throws Exception {
    createIndex("test");
    ensureGreen();
    int numDocs = randomIntBetween(100, 150);
    IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i), "field2", i);
    }
    indexRandom(true, docs);
    refresh();
    QueryBuilder q = QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one"))));
    logger.info("Query: {}", q);
    SearchResponse resp = client().prepareSearch().setQuery(q).setProfile(true).setSearchType(SearchType.QUERY_THEN_FETCH).execute().actionGet();
    assertNotNull("Profile response element should not be null", resp.getProfileResults());
    assertThat("Profile response should not be an empty array", resp.getProfileResults().size(), not(0));
    for (Map.Entry<String, ProfileShardResult> shardResult : resp.getProfileResults().entrySet()) {
        for (QueryProfileShardResult searchProfiles : shardResult.getValue().getQueryProfileResults()) {
            for (ProfileResult result : searchProfiles.getQueryResults()) {
                assertNotNull(result.getQueryName());
                assertNotNull(result.getLuceneDescription());
                assertThat(result.getTime(), greaterThan(0L));
                assertNotNull(result.getTimeBreakdown());
            }
            CollectorResult result = searchProfiles.getCollectorResult();
            assertThat(result.getName(), not(isEmptyOrNullString()));
            assertThat(result.getTime(), greaterThan(0L));
        }
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ProfileResult(org.elasticsearch.search.profile.ProfileResult) RandomQueryGenerator.randomQueryBuilder(org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Map(java.util.Map) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult)

Aggregations

ProfileShardResult (org.elasticsearch.search.profile.ProfileShardResult)19 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 ProfileResult (org.elasticsearch.search.profile.ProfileResult)14 Map (java.util.Map)9 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)9 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)9 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)9 RandomQueryGenerator.randomQueryBuilder (org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder)9 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)9 AggregationProfileShardResult (org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)6 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)6 ArrayList (java.util.ArrayList)2 TopDocs (org.apache.lucene.search.TopDocs)2 GlobalOrdinalsStringTermsAggregator (org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 AbstractList (java.util.AbstractList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Term (org.apache.lucene.index.Term)1