From ee4ce8ecec6acfe38f78c572c758db451a49093c Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Wed, 20 May 2020 08:22:13 -0400 Subject: [PATCH] Fix geotile_grid group_by field mapping (#56939) (#56990) The original implementation utilized `bbox` as the index mapping type. This would not work as it would have to be `envelope`. But, given that `envelope` and `polygon` are tessellated in the same way, we choose to use `polygon` as the geo_shape type. This is for easier support other places in the stack (a la kibana maps) --- .../transforms/pivot/GeoTileGroupSource.java | 15 +++++++++++---- .../integration/TransformPivotRestIT.java | 9 ++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GeoTileGroupSource.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GeoTileGroupSource.java index 3f4b25252af..0f50aa6cd05 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GeoTileGroupSource.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GeoTileGroupSource.java @@ -9,6 +9,7 @@ package org.elasticsearch.xpack.core.transform.transforms.pivot; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.parsers.ShapeParser; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -26,6 +27,7 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -172,12 +174,17 @@ public class GeoTileGroupSource extends SingleGroupSource { assert key instanceof String; Rectangle rectangle = GeoTileUtils.toBoundingBox(key.toString()); final Map geoShape = new HashMap<>(); - geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), "BBOX"); + geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName()); geoShape.put( ShapeParser.FIELD_COORDINATES.getPreferredName(), - Arrays.asList( - new Double[] { rectangle.getMinLon(), rectangle.getMaxLat() }, - new Double[] { rectangle.getMaxLon(), rectangle.getMinLat() } + Collections.singletonList( + Arrays.asList( + new Double[] { rectangle.getMaxLon(), rectangle.getMinLat() }, + new Double[] { rectangle.getMinLon(), rectangle.getMinLat() }, + new Double[] { rectangle.getMinLon(), rectangle.getMaxLat() }, + new Double[] { rectangle.getMaxLon(), rectangle.getMaxLat() }, + new Double[] { rectangle.getMaxLon(), rectangle.getMinLat() } + ) ) ); return geoShape; diff --git a/x-pack/plugin/transform/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/transform/integration/TransformPivotRestIT.java b/x-pack/plugin/transform/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/transform/integration/TransformPivotRestIT.java index 3e39f2cbb8d..0c1f81f6003 100644 --- a/x-pack/plugin/transform/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/transform/integration/TransformPivotRestIT.java +++ b/x-pack/plugin/transform/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/transform/integration/TransformPivotRestIT.java @@ -1083,12 +1083,15 @@ public class TransformPivotRestIT extends TransformRestTestCase { "hits.hits._source.tile", searchResult )).get(0); - assertThat(actualObj.get("type"), equalTo("BBOX")); - List> coordinates = (List>) actualObj.get("coordinates"); + assertThat(actualObj.get("type"), equalTo("polygon")); + List> coordinates = ((List>>) actualObj.get("coordinates")).get(0); assertThat(coordinates, is(not(nullValue()))); - assertThat(coordinates, hasSize(2)); + assertThat(coordinates, hasSize(5)); assertThat(coordinates.get(0), hasSize(2)); assertThat(coordinates.get(1), hasSize(2)); + assertThat(coordinates.get(2), hasSize(2)); + assertThat(coordinates.get(3), hasSize(2)); + assertThat(coordinates.get(4), hasSize(2)); } public void testPivotWithWeightedAvgAgg() throws Exception {