|
19 | 19 | package org.elasticsearch.search.aggregations.bucket.geogrid;
|
20 | 20 |
|
21 | 21 | import org.apache.lucene.util.PriorityQueue;
|
| 22 | +import org.elasticsearch.common.ParseField; |
22 | 23 | import org.elasticsearch.common.geo.GeoPoint;
|
23 | 24 | import org.elasticsearch.common.io.stream.StreamInput;
|
24 | 25 | import org.elasticsearch.common.io.stream.StreamOutput;
|
25 | 26 | import org.elasticsearch.common.util.LongObjectPagedHashMap;
|
26 | 27 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
| 28 | +import org.elasticsearch.rest.action.search.RestSearchAction; |
27 | 29 | import org.elasticsearch.search.aggregations.Aggregations;
|
28 | 30 | import org.elasticsearch.search.aggregations.InternalAggregation;
|
29 | 31 | import org.elasticsearch.search.aggregations.InternalAggregations;
|
@@ -154,6 +156,8 @@ public int hashCode() {
|
154 | 156 |
|
155 | 157 | }
|
156 | 158 |
|
| 159 | + static final ParseField HASH_TYPE_FIELD = new ParseField("hash_type"); |
| 160 | + |
157 | 161 | private final int requiredSize;
|
158 | 162 | private final List<Bucket> buckets;
|
159 | 163 |
|
@@ -238,6 +242,17 @@ public InternalGeoHashGrid doReduce(List<InternalAggregation> aggregations, Redu
|
238 | 242 |
|
239 | 243 | @Override
|
240 | 244 | public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
| 245 | + // not sure we should re-use RestSearchAction.TYPED_KEYS_PARAM here, but we already use it in |
| 246 | + // suggestions and aggregations and it should be switched on by every high level client reqeust |
| 247 | + if (params.paramAsBoolean(RestSearchAction.TYPED_KEYS_PARAM, false)) { |
| 248 | + if (buckets.isEmpty() == false) { |
| 249 | + // TODO this assume all types in the buckets are same, but we should really keep this |
| 250 | + // info in the aggregation itself |
| 251 | + // TODO the GeoHashType needs a better method to get some sort of ID for it, name() or toString() |
| 252 | + // seem to brittle for me tbh |
| 253 | + builder.field(HASH_TYPE_FIELD.getPreferredName(), buckets.get(0).type.toString()); |
| 254 | + } |
| 255 | + } |
241 | 256 | builder.startArray(CommonFields.BUCKETS.getPreferredName());
|
242 | 257 | for (Bucket bucket : buckets) {
|
243 | 258 | bucket.toXContent(builder, params);
|
|
0 commit comments