diff --git a/docs/changelog/84229.yaml b/docs/changelog/84229.yaml new file mode 100644 index 0000000000000..a114f0f559f37 --- /dev/null +++ b/docs/changelog/84229.yaml @@ -0,0 +1,6 @@ +pr: 84229 +summary: Normalise polygons only when necessary +area: Geo +type: enhancement +issues: + - 35349 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; } 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..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("at least 4 polygon points required")); + assertThat(exception.getCause().getMessage(), containsString("at least three non-collinear points required")); } }