Search in sources :

Example 6 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult 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 7 with ProfileResult

use of org.elasticsearch.search.profile.ProfileResult 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)

Example 8 with ProfileResult

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

the class AggregationProfileShardResult method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startArray(AGGREGATIONS);
    for (ProfileResult p : aggProfileResults) {
        p.toXContent(builder, params);
    }
    builder.endArray();
    return builder;
}
Also used : ProfileResult(org.elasticsearch.search.profile.ProfileResult)

Example 9 with ProfileResult

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

the class QueryProfileShardResult method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.startArray(QUERY_ARRAY);
    for (ProfileResult p : queryProfileResults) {
        p.toXContent(builder, params);
    }
    builder.endArray();
    builder.field(REWRITE_TIME, rewriteTime);
    builder.startArray(COLLECTOR);
    profileCollector.toXContent(builder, params);
    builder.endArray();
    builder.endObject();
    return builder;
}
Also used : ProfileResult(org.elasticsearch.search.profile.ProfileResult)

Example 10 with ProfileResult

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

the class QueryProfileShardResult method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(queryProfileResults.size());
    for (ProfileResult p : queryProfileResults) {
        p.writeTo(out);
    }
    profileCollector.writeTo(out);
    out.writeLong(rewriteTime);
}
Also used : ProfileResult(org.elasticsearch.search.profile.ProfileResult)

Aggregations

ProfileResult (org.elasticsearch.search.profile.ProfileResult)22 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ProfileShardResult (org.elasticsearch.search.profile.ProfileShardResult)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)5 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 Term (org.apache.lucene.index.Term)4 Query (org.apache.lucene.search.Query)4 RandomApproximationQuery (org.apache.lucene.search.RandomApproximationQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4 GlobalOrdinalsStringTermsAggregator (org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)1