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);
}
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);
}
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));
}
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);
}
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;
}
Aggregations