|
10 | 10 | import org.elasticsearch.ElasticsearchException;
|
11 | 11 | import org.elasticsearch.common.Numbers;
|
12 | 12 | import org.elasticsearch.common.geo.GeoPoint;
|
13 |
| -import org.elasticsearch.common.geo.builders.LineStringBuilder; |
14 |
| -import org.elasticsearch.common.geo.builders.PointBuilder; |
15 |
| -import org.elasticsearch.common.geo.builders.PolygonBuilder; |
16 |
| -import org.elasticsearch.common.geo.parsers.ShapeParser; |
| 13 | + |
17 | 14 | import org.elasticsearch.geometry.Rectangle;
|
18 | 15 | import org.elasticsearch.index.mapper.DateFieldMapper;
|
19 | 16 | import org.elasticsearch.search.aggregations.Aggregation;
|
@@ -82,6 +79,12 @@ public final class AggregationResultUtils {
|
82 | 79 | BUCKET_KEY_EXTRACTOR_MAP = Collections.unmodifiableMap(tempMap);
|
83 | 80 | }
|
84 | 81 |
|
| 82 | + private static final String FIELD_TYPE = "type"; |
| 83 | + private static final String FIELD_COORDINATES = "coordinates"; |
| 84 | + private static final String POINT = "point"; |
| 85 | + private static final String LINESTRING = "linestring"; |
| 86 | + private static final String POLYGON = "polygon"; |
| 87 | + |
85 | 88 | /**
|
86 | 89 | * Extracts aggregation results from a composite aggregation and puts it into a map.
|
87 | 90 | *
|
@@ -413,29 +416,29 @@ public Object value(Aggregation agg, Map<String, String> fieldTypeMap, String lo
|
413 | 416 | final Map<String, Object> geoShape = new HashMap<>();
|
414 | 417 | // If the two geo_points are equal, it is a point
|
415 | 418 | if (aggregation.topLeft().equals(aggregation.bottomRight())) {
|
416 |
| - geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PointBuilder.TYPE.shapeName()); |
| 419 | + geoShape.put(FIELD_TYPE, POINT); |
417 | 420 | geoShape.put(
|
418 |
| - ShapeParser.FIELD_COORDINATES.getPreferredName(), |
| 421 | + FIELD_COORDINATES, |
419 | 422 | Arrays.asList(aggregation.topLeft().getLon(), aggregation.bottomRight().getLat())
|
420 | 423 | );
|
421 | 424 | // If only the lat or the lon of the two geo_points are equal, than we know it should be a line
|
422 | 425 | } else if (Double.compare(aggregation.topLeft().getLat(), aggregation.bottomRight().getLat()) == 0
|
423 | 426 | || Double.compare(aggregation.topLeft().getLon(), aggregation.bottomRight().getLon()) == 0) {
|
424 |
| - geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), LineStringBuilder.TYPE.shapeName()); |
| 427 | + geoShape.put(FIELD_TYPE, LINESTRING); |
425 | 428 | geoShape.put(
|
426 |
| - ShapeParser.FIELD_COORDINATES.getPreferredName(), |
| 429 | + FIELD_COORDINATES, |
427 | 430 | Arrays.asList(
|
428 | 431 | new Double[] { aggregation.topLeft().getLon(), aggregation.topLeft().getLat() },
|
429 | 432 | new Double[] { aggregation.bottomRight().getLon(), aggregation.bottomRight().getLat() }
|
430 | 433 | )
|
431 | 434 | );
|
432 | 435 | } else {
|
433 | 436 | // neither points are equal, we have a polygon that is a square
|
434 |
| - geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName()); |
| 437 | + geoShape.put(FIELD_TYPE, POLYGON); |
435 | 438 | final GeoPoint tl = aggregation.topLeft();
|
436 | 439 | final GeoPoint br = aggregation.bottomRight();
|
437 | 440 | geoShape.put(
|
438 |
| - ShapeParser.FIELD_COORDINATES.getPreferredName(), |
| 441 | + FIELD_COORDINATES, |
439 | 442 | Collections.singletonList(
|
440 | 443 | Arrays.asList(
|
441 | 444 | new Double[] { tl.getLon(), tl.getLat() },
|
@@ -468,9 +471,9 @@ public Object value(Object key, String type) {
|
468 | 471 | assert key instanceof String;
|
469 | 472 | Rectangle rectangle = GeoTileUtils.toBoundingBox(key.toString());
|
470 | 473 | final Map<String, Object> geoShape = new HashMap<>();
|
471 |
| - geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName()); |
| 474 | + geoShape.put(FIELD_TYPE, POLYGON); |
472 | 475 | geoShape.put(
|
473 |
| - ShapeParser.FIELD_COORDINATES.getPreferredName(), |
| 476 | + FIELD_COORDINATES, |
474 | 477 | Collections.singletonList(
|
475 | 478 | Arrays.asList(
|
476 | 479 | new Double[] { rectangle.getMaxLon(), rectangle.getMinLat() },
|
|
0 commit comments