Skip to content

Commit

Permalink
Changed the respnose structure of the percentiles aggregation where n…
Browse files Browse the repository at this point in the history
…ow all the percentiles are placed under a `values` object (or `values` array in case the `keyed` flag is set to `false`

Closes #5870
  • Loading branch information
uboness committed May 7, 2014
1 parent 8008432 commit e0523d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Expand Up @@ -57,22 +57,27 @@ percentiles: `[ 1, 5, 25, 50, 75, 95, 99 ]`. The response will look like this:
"aggregations": {
"load_time_outlier": {
"1.0": 15,
"5.0": 20,
"25.0": 23,
"50.0": 25,
"75.0": 29,
"95.0": 60,
"99.0": 150
"values" : {
"1.0": 15,
"5.0": 20,
"25.0": 23,
"50.0": 25,
"75.0": 29,
"95.0": 60,
"99.0": 150
}
}
}
}
--------------------------------------------------

WARNING: added[1.2.0] The above response structure applies for `1.2.0` and above. Pre `1.2.0` release, the `values` object was
missing and all the percentiles where placed directly under the aggregation name object

As you can see, the aggregation will return a calculated value for each percentile
in the default range. If we assume response times are in milliseconds, it is
immediately obvious that the webpage normally loads in 15-30ms, but occasionally
spikes to 60-150ms.
spikes to 60-150ms.

Often, administrators are only interested in outliers -- the extreme percentiles.
We can specify just the percents we are interested in (requested percentiles
Expand Down
Expand Up @@ -157,6 +157,7 @@ protected static void writeSize(int size, StreamOutput out) throws IOException {
public static final class CommonFields {
public static final XContentBuilderString BUCKETS = new XContentBuilderString("buckets");
public static final XContentBuilderString VALUE = new XContentBuilderString("value");
public static final XContentBuilderString VALUES = new XContentBuilderString("values");
public static final XContentBuilderString VALUE_AS_STRING = new XContentBuilderString("value_as_string");
public static final XContentBuilderString DOC_COUNT = new XContentBuilderString("doc_count");
public static final XContentBuilderString KEY = new XContentBuilderString("key");
Expand Down
Expand Up @@ -137,8 +137,9 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name);
if (keyed) {
builder.startObject(name);
builder.startObject(CommonFields.VALUES);
for(int i = 0; i < percents.length; ++i) {
String key = String.valueOf(percents[i]);
double value = percentile(percents[i]);
Expand All @@ -149,7 +150,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
builder.endObject();
} else {
builder.startArray(name);
builder.startArray(CommonFields.VALUES);
for (int i = 0; i < percents.length; i++) {
double value = percentile(percents[i]);
builder.startObject();
Expand All @@ -162,6 +163,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
builder.endArray();
}
builder.endObject();
return builder;
}

Expand Down

0 comments on commit e0523d3

Please sign in to comment.