Search in sources :

Example 1 with QueryProfileShardResult

use of org.elasticsearch.search.profile.query.QueryProfileShardResult in project elasticsearch by elastic.

the class ProfileShardResult method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(queryProfileResults.size());
    for (QueryProfileShardResult queryShardResult : queryProfileResults) {
        queryShardResult.writeTo(out);
    }
    aggProfileShardResult.writeTo(out);
}
Also used : QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult)

Example 2 with QueryProfileShardResult

use of org.elasticsearch.search.profile.query.QueryProfileShardResult in project elasticsearch by elastic.

the class SearchProfileShardResults method buildShardResults.

/**
     * Helper method to convert Profiler into InternalProfileShardResults, which
     * can be serialized to other nodes, emitted as JSON, etc.
     *
     * @param profilers
     *            The {@link Profilers} to convert into results
     * @return A {@link ProfileShardResult} representing the results for this
     *         shard
     */
public static ProfileShardResult buildShardResults(Profilers profilers) {
    List<QueryProfiler> queryProfilers = profilers.getQueryProfilers();
    AggregationProfiler aggProfiler = profilers.getAggregationProfiler();
    List<QueryProfileShardResult> queryResults = new ArrayList<>(queryProfilers.size());
    for (QueryProfiler queryProfiler : queryProfilers) {
        QueryProfileShardResult result = new QueryProfileShardResult(queryProfiler.getTree(), queryProfiler.getRewriteTime(), queryProfiler.getCollector());
        queryResults.add(result);
    }
    AggregationProfileShardResult aggResults = new AggregationProfileShardResult(aggProfiler.getTree());
    return new ProfileShardResult(queryResults, aggResults);
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) AggregationProfiler(org.elasticsearch.search.profile.aggregation.AggregationProfiler) ArrayList(java.util.ArrayList) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 3 with QueryProfileShardResult

use of org.elasticsearch.search.profile.query.QueryProfileShardResult in project elasticsearch by elastic.

the class SearchProfileShardResults method parseSearchProfileResultsEntry.

private static void parseSearchProfileResultsEntry(XContentParser parser, Map<String, ProfileShardResult> searchProfileResults) throws IOException {
    XContentParser.Token token = parser.currentToken();
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
    List<QueryProfileShardResult> queryProfileResults = new ArrayList<>();
    AggregationProfileShardResult aggProfileShardResult = null;
    String id = null;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (ID_FIELD.equals(currentFieldName)) {
                id = parser.text();
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (SEARCHES_FIELD.equals(currentFieldName)) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    queryProfileResults.add(QueryProfileShardResult.fromXContent(parser));
                }
            } else if (AggregationProfileShardResult.AGGREGATIONS.equals(currentFieldName)) {
                aggProfileShardResult = AggregationProfileShardResult.fromXContent(parser);
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else {
            throwUnknownToken(token, parser.getTokenLocation());
        }
    }
    searchProfileResults.put(id, new ProfileShardResult(queryProfileResults, aggProfileShardResult));
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) ArrayList(java.util.ArrayList) XContentParser(org.elasticsearch.common.xcontent.XContentParser) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 4 with QueryProfileShardResult

use of org.elasticsearch.search.profile.query.QueryProfileShardResult in project elasticsearch by elastic.

the class SearchProfileShardResultsTests method createTestItem.

public static SearchProfileShardResults createTestItem() {
    int size = rarely() ? 0 : randomIntBetween(1, 2);
    Map<String, ProfileShardResult> searchProfileResults = new HashMap<>(size);
    for (int i = 0; i < size; i++) {
        List<QueryProfileShardResult> queryProfileResults = new ArrayList<>();
        int queryItems = rarely() ? 0 : randomIntBetween(1, 2);
        for (int q = 0; q < queryItems; q++) {
            queryProfileResults.add(QueryProfileShardResultTests.createTestItem());
        }
        AggregationProfileShardResult aggProfileShardResult = AggregationProfileShardResultTests.createTestItem(1);
        searchProfileResults.put(randomAsciiOfLengthBetween(5, 10), new ProfileShardResult(queryProfileResults, aggProfileShardResult));
    }
    return new SearchProfileShardResults(searchProfileResults);
}
Also used : AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult) HashMap(java.util.HashMap) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) ArrayList(java.util.ArrayList) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Example 5 with QueryProfileShardResult

use of org.elasticsearch.search.profile.query.QueryProfileShardResult in project elasticsearch by elastic.

the class SearchProfileShardResults method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(PROFILE_FIELD).startArray(SHARDS_FIELD);
    // shardResults is a map, but we print entries in a json array, which is ordered.
    // we sort the keys of the map, so that toXContent always prints out the same array order
    TreeSet<String> sortedKeys = new TreeSet<>(shardResults.keySet());
    for (String key : sortedKeys) {
        builder.startObject();
        builder.field(ID_FIELD, key);
        builder.startArray(SEARCHES_FIELD);
        ProfileShardResult profileShardResult = shardResults.get(key);
        for (QueryProfileShardResult result : profileShardResult.getQueryProfileResults()) {
            result.toXContent(builder, params);
        }
        builder.endArray();
        profileShardResult.getAggregationProfileResults().toXContent(builder, params);
        builder.endObject();
    }
    builder.endArray().endObject();
    return builder;
}
Also used : QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) TreeSet(java.util.TreeSet) QueryProfileShardResult(org.elasticsearch.search.profile.query.QueryProfileShardResult) AggregationProfileShardResult(org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)

Aggregations

QueryProfileShardResult (org.elasticsearch.search.profile.query.QueryProfileShardResult)5 AggregationProfileShardResult (org.elasticsearch.search.profile.aggregation.AggregationProfileShardResult)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 AggregationProfiler (org.elasticsearch.search.profile.aggregation.AggregationProfiler)1 QueryProfiler (org.elasticsearch.search.profile.query.QueryProfiler)1