From 339d10c16f7bae5cd9994c9e396e5441eba84bba Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Fri, 20 Dec 2019 04:47:42 -1000 Subject: [PATCH] Geo: Switch generated GeoJson type names to camel case (#50400) Switches generated GeoJson type names to camel case to conform to the standard. Closes #49568 --- .../ingest/processors/circle.asciidoc | 2 +- .../org/elasticsearch/common/geo/GeoJson.java | 18 +++++++++--------- .../common/geo/GeometryParserTests.java | 4 ++-- .../index/query/GeoShapeQueryBuilderTests.java | 2 +- .../index/query/ShapeQueryBuilderTests.java | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/reference/ingest/processors/circle.asciidoc b/docs/reference/ingest/processors/circle.asciidoc index 2ba3897b6f58b..bbcf9d5ae1d71 100644 --- a/docs/reference/ingest/processors/circle.asciidoc +++ b/docs/reference/ingest/processors/circle.asciidoc @@ -130,7 +130,7 @@ The response from the above index request: [30.000365257263184, 10.0] ] ], - "type": "polygon" + "type": "Polygon" } } } diff --git a/server/src/main/java/org/elasticsearch/common/geo/GeoJson.java b/server/src/main/java/org/elasticsearch/common/geo/GeoJson.java index 06b3027fe64d8..9324d50d8e122 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/GeoJson.java +++ b/server/src/main/java/org/elasticsearch/common/geo/GeoJson.java @@ -382,17 +382,17 @@ public static String getGeoJsonName(Geometry geometry) { return geometry.visit(new GeometryVisitor() { @Override public String visit(Circle circle) { - return "circle"; + return "Circle"; } @Override public String visit(GeometryCollection collection) { - return "geometrycollection"; + return "GeometryCollection"; } @Override public String visit(Line line) { - return "linestring"; + return "LineString"; } @Override @@ -402,32 +402,32 @@ public String visit(LinearRing ring) { @Override public String visit(MultiLine multiLine) { - return "multilinestring"; + return "MultiLineString"; } @Override public String visit(MultiPoint multiPoint) { - return "multipoint"; + return "MultiPoint"; } @Override public String visit(MultiPolygon multiPolygon) { - return "multipolygon"; + return "MultiPolygon"; } @Override public String visit(Point point) { - return "point"; + return "Point"; } @Override public String visit(Polygon polygon) { - return "polygon"; + return "Polygon"; } @Override public String visit(Rectangle rectangle) { - return "envelope"; + return "Envelope"; } }); } diff --git a/server/src/test/java/org/elasticsearch/common/geo/GeometryParserTests.java b/server/src/test/java/org/elasticsearch/common/geo/GeometryParserTests.java index df4b47f23689f..4c53d40fb75db 100644 --- a/server/src/test/java/org/elasticsearch/common/geo/GeometryParserTests.java +++ b/server/src/test/java/org/elasticsearch/common/geo/GeometryParserTests.java @@ -51,7 +51,7 @@ public void testGeoJsonParsing() throws Exception { assertEquals(new Point(100, 0), format.fromXContent(parser)); XContentBuilder newGeoJson = XContentFactory.jsonBuilder(); format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS); - assertEquals("{\"type\":\"point\",\"coordinates\":[100.0,10.0]}", Strings.toString(newGeoJson)); + assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,10.0]}", Strings.toString(newGeoJson)); } XContentBuilder pointGeoJsonWithZ = XContentFactory.jsonBuilder() @@ -148,7 +148,7 @@ public void testNullParsing() throws Exception { // if we serialize non-null value - it should be serialized as geojson format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS); newGeoJson.endObject(); - assertEquals("{\"val\":{\"type\":\"point\",\"coordinates\":[100.0,10.0]}}", Strings.toString(newGeoJson)); + assertEquals("{\"val\":{\"type\":\"Point\",\"coordinates\":[100.0,10.0]}}", Strings.toString(newGeoJson)); newGeoJson = XContentFactory.jsonBuilder().startObject().field("val"); format.toXContent(null, newGeoJson, ToXContent.EMPTY_PARAMS); diff --git a/server/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java index 9395355dd25ed..78973133d0ee4 100644 --- a/server/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java @@ -210,7 +210,7 @@ public void testFromJson() throws IOException { " \"geo_shape\" : {\n" + " \"location\" : {\n" + " \"shape\" : {\n" + - " \"type\" : \"envelope\",\n" + + " \"type\" : \"Envelope\",\n" + " \"coordinates\" : [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ]\n" + " },\n" + " \"relation\" : \"intersects\"\n" + diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilderTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilderTests.java index 00c30e9e9d44a..99eb4c335eb81 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilderTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilderTests.java @@ -182,7 +182,7 @@ public void testFromJson() throws IOException { " }\n" + "}"; ShapeQueryBuilder parsed = (ShapeQueryBuilder) parseQuery(json); - checkGeneratedJson(json, parsed); + checkGeneratedJson(json.replaceAll("envelope", "Envelope"), parsed); assertEquals(json, 42.0, parsed.boost(), 0.0001); }