Aggregations: Fixed Histogram key_as_string bug
The key as string field in the response for the histogram aggregation will now only show if format is specified on the request. Closes #6655
This commit is contained in:
parent
d6cd2c2b73
commit
8260138e59
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
"Basic test":
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
body: { "number" : 1 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 2
|
||||
body: { "number" : 51 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 3
|
||||
body: { "number" : 101 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 4
|
||||
body: { "number" : 151 }
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
search:
|
||||
body: { "aggs" : { "histo" : { "histogram" : { "field" : "number", "interval" : 50 } } } }
|
||||
|
||||
- match: { hits.total: 4 }
|
||||
|
||||
- length: { aggregations.histo.buckets: 4 }
|
||||
|
||||
- match: { aggregations.histo.buckets.0.key: 0 }
|
||||
|
||||
- is_false: aggregations.histo.buckets.0.key_as_string
|
||||
|
||||
- match: { aggregations.histo.buckets.0.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.1.key: 50 }
|
||||
|
||||
- is_false: aggregations.histo.buckets.1.key_as_string
|
||||
|
||||
- match: { aggregations.histo.buckets.1.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.2.key: 100 }
|
||||
|
||||
- is_false: aggregations.histo.buckets.2.key_as_string
|
||||
|
||||
- match: { aggregations.histo.buckets.2.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.3.key: 150 }
|
||||
|
||||
- is_false: aggregations.histo.buckets.3.key_as_string
|
||||
|
||||
- match: { aggregations.histo.buckets.3.doc_count: 1 }
|
||||
|
||||
---
|
||||
"Format test":
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
body: { "number" : 1 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 2
|
||||
body: { "number" : 51 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 3
|
||||
body: { "number" : 101 }
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 4
|
||||
body: { "number" : 151 }
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
search:
|
||||
body: { "aggs" : { "histo" : { "histogram" : { "field" : "number", "interval" : 50, "format" : "Value is ##0.0" } } } }
|
||||
|
||||
- match: { hits.total: 4 }
|
||||
|
||||
- length: { aggregations.histo.buckets: 4 }
|
||||
|
||||
- match: { aggregations.histo.buckets.0.key: 0 }
|
||||
|
||||
- match: { aggregations.histo.buckets.0.key_as_string: "Value is 0.0" }
|
||||
|
||||
- match: { aggregations.histo.buckets.0.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.1.key: 50 }
|
||||
|
||||
- match: { aggregations.histo.buckets.1.key_as_string: "Value is 50.0" }
|
||||
|
||||
- match: { aggregations.histo.buckets.1.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.2.key: 100 }
|
||||
|
||||
- match: { aggregations.histo.buckets.2.key_as_string: "Value is 100.0" }
|
||||
|
||||
- match: { aggregations.histo.buckets.2.doc_count: 1 }
|
||||
|
||||
- match: { aggregations.histo.buckets.3.key: 150 }
|
||||
|
||||
- match: { aggregations.histo.buckets.3.key_as_string: "Value is 150.0" }
|
||||
|
||||
- match: { aggregations.histo.buckets.3.doc_count: 1 }
|
|
@ -120,7 +120,7 @@ public class InternalHistogram<B extends InternalHistogram.Bucket> extends Inter
|
|||
}
|
||||
|
||||
void toXContent(XContentBuilder builder, Params params, boolean keyed, @Nullable ValueFormatter formatter) throws IOException {
|
||||
if (formatter != null) {
|
||||
if (formatter != null && formatter != ValueFormatter.RAW) {
|
||||
Text keyTxt = new StringText(formatter.format(key));
|
||||
if (keyed) {
|
||||
builder.startObject(keyTxt.string());
|
||||
|
|
Loading…
Reference in New Issue