List<String> perCompetitorIndices = new ArrayList<>();
while ((token = p.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.VALUE_STRING) {
perCompetitorIndices.add(p.text());
} else {
throw new ElasticsearchParseException("Failed parsing array field [" + fieldName + "] expected string values but got: " + token);
}
}
builder.setIndices(perCompetitorIndices.toArray(new String[perCompetitorIndices.size()]));
} else if ("types".equals(fieldName)) {
List<String> perCompetitorTypes = new ArrayList<>();
while ((token = p.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.VALUE_STRING) {
perCompetitorTypes.add(p.text());
} else {
throw new ElasticsearchParseException("Failed parsing array field [" + fieldName + "] expected string values but got: " + token);
}
}
builder.setTypes(perCompetitorTypes.toArray(new String[perCompetitorTypes.size()]));
} else {
throw new ElasticsearchParseException("Failed parsing array field [" + fieldName + "] field is not recognized");
}
break;
case START_OBJECT:
if ("clear_caches".equals(fieldName)) {
BenchmarkSettings.ClearCachesSettings clearCachesSettings = new BenchmarkSettings.ClearCachesSettings();
builder.setClearCachesSettings(clearCachesSettings);
parseClearCaches(p, clearCachesSettings);
} else {
throw new ElasticsearchParseException("Failed parsing object field [" + fieldName + "] field is not recognized");
}
break;
case FIELD_NAME:
fieldName = p.text();
break;
case VALUE_NUMBER:
if ("multiplier".equals(fieldName)) {
builder.setMultiplier(p.intValue());
} else if ("num_slowest".equals(fieldName)) {
builder.setNumSlowest(p.intValue());
} else if ("iterations".equals(fieldName)) {
builder.setIterations(p.intValue());
} else if ("concurrency".equals(fieldName)) {
builder.setConcurrency(p.intValue());
} else {
throw new ElasticsearchParseException("Failed parsing numeric field [" + fieldName + "] field is not recognized");
}
break;
case VALUE_BOOLEAN:
if ("warmup".equals(fieldName)) {
builder.setWarmup(p.booleanValue());
} else if ("clear_caches".equals(fieldName)) {
if (p.booleanValue()) {
throw new ElasticsearchParseException("Failed parsing field [" + fieldName + "] must specify which caches to clear");
} else {
builder.setAllowCacheClearing(false);
}
} else {
throw new ElasticsearchParseException("Failed parsing boolean field [" + fieldName + "] field is not recognized");
}
break;
case VALUE_STRING:
if ("name".equals(fieldName)) {
builder.setName(p.text());
} else if ("search_type".equals(fieldName) || "searchType".equals(fieldName)) {
builder.setSearchType(SearchType.fromString(p.text()));
} else {
throw new ElasticsearchParseException("Failed parsing string field [" + fieldName + "] field is not recognized");
}
break;
default:
throw new ElasticsearchParseException("Failed parsing " + token.name() + " field [" + fieldName + "] field is not recognized");
}
}
return builder;
}