From e91cc3af0e7d4d4f94feb207f4c99bd4a0d941e6 Mon Sep 17 00:00:00 2001 From: iverase Date: Tue, 22 Feb 2022 14:46:59 +0100 Subject: [PATCH 1/5] Normalize polygons only when necessary --- .../org/elasticsearch/index/mapper/GeoShapeIndexer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java index ebc1e208d267a..ad57b8fe6a4d0 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java @@ -51,7 +51,9 @@ public List indexShape(Geometry geometry) { if (geometry == null) { return Collections.emptyList(); } - geometry = GeometryNormalizer.apply(orientation, geometry); + if (GeometryNormalizer.needsNormalize(orientation, geometry)) { + geometry = GeometryNormalizer.apply(orientation, geometry); + } LuceneGeometryIndexer visitor = new LuceneGeometryIndexer(name); geometry.visit(visitor); return visitor.fields(); @@ -125,7 +127,7 @@ public Void visit(Point point) { @Override public Void visit(Polygon polygon) { - addFields(LatLonShape.createIndexableFields(name, GeoShapeUtils.toLucenePolygon(polygon))); + addFields(LatLonShape.createIndexableFields(name, GeoShapeUtils.toLucenePolygon(polygon), true)); return null; } From d32e0ac8cfcc3f70f112ec82ce76d2f0103e9a9a Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Tue, 22 Feb 2022 14:50:35 +0100 Subject: [PATCH 2/5] Update docs/changelog/84229.yaml --- docs/changelog/84229.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/84229.yaml diff --git a/docs/changelog/84229.yaml b/docs/changelog/84229.yaml new file mode 100644 index 0000000000000..b2279ee037c83 --- /dev/null +++ b/docs/changelog/84229.yaml @@ -0,0 +1,5 @@ +pr: 84229 +summary: Normalise polygons only when necessary +area: Geo +type: enhancement +issues: [] From e1b339b3d86777138b884a6d4d9079d1d8b33873 Mon Sep 17 00:00:00 2001 From: iverase Date: Tue, 22 Feb 2022 15:47:28 +0100 Subject: [PATCH 3/5] fix test --- .../index/mapper/GeoShapeWithDocValuesFieldMapperTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java index 51f314e82fda7..2ce5aa560fc66 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java @@ -254,7 +254,7 @@ public void testIgnoreMalformedValues() throws IOException { ParsedDocument document = ignoreMapper.parse(sourceToParse); assertThat(document.docs().get(0).getFields("field").length, equalTo(0)); MapperParsingException exception = expectThrows(MapperParsingException.class, () -> failMapper.parse(sourceToParse)); - assertThat(exception.getCause().getMessage(), containsString("at least 4 polygon points required")); + assertThat(exception.getCause().getMessage(), containsString("Unable to Tessellate shape")); } } From 9e02e85f6c99154da02bc5a730ba0951ce0ebab3 Mon Sep 17 00:00:00 2001 From: iverase Date: Mon, 7 Mar 2022 10:13:34 +0100 Subject: [PATCH 4/5] fix test --- .../index/mapper/GeoShapeWithDocValuesFieldMapperTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java index 2ce5aa560fc66..fe1f82fde5ea3 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java @@ -254,7 +254,7 @@ public void testIgnoreMalformedValues() throws IOException { ParsedDocument document = ignoreMapper.parse(sourceToParse); assertThat(document.docs().get(0).getFields("field").length, equalTo(0)); MapperParsingException exception = expectThrows(MapperParsingException.class, () -> failMapper.parse(sourceToParse)); - assertThat(exception.getCause().getMessage(), containsString("Unable to Tessellate shape")); + assertThat(exception.getCause().getMessage(), containsString("at least three non-collinear points required")); } } From 858a7d36c27dc3c4f3941eac8cd459cfa07cc779 Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Mon, 7 Mar 2022 10:19:29 +0100 Subject: [PATCH 5/5] Update docs/changelog/84229.yaml --- docs/changelog/84229.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog/84229.yaml b/docs/changelog/84229.yaml index b2279ee037c83..a114f0f559f37 100644 --- a/docs/changelog/84229.yaml +++ b/docs/changelog/84229.yaml @@ -2,4 +2,5 @@ pr: 84229 summary: Normalise polygons only when necessary area: Geo type: enhancement -issues: [] +issues: + - 35349