From 795d0462191b454b9a5fe0cf41f31293c9f67718 Mon Sep 17 00:00:00 2001 From: Christos Soulios Date: Wed, 27 Nov 2019 15:07:19 +0200 Subject: [PATCH 1/3] Fix small typo in GeoPointFieldMapper null_value It seems that code was pasted but not fully changed --- .../org/elasticsearch/index/mapper/GeoPointFieldMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index f84079fc3f4d2..f319db284b2d2 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -160,7 +160,7 @@ public Mapper.Builder parse(String name, Map node, ParserContext if (nullValue != null) { boolean ignoreZValue = builder.ignoreZValue == null ? Defaults.IGNORE_Z_VALUE.value() : builder.ignoreZValue; - boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreZValue; + boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreMalformed; GeoPoint point = GeoUtils.parseGeoPoint(nullValue, ignoreZValue); if (ignoreMalformed == false) { if (point.lat() > 90.0 || point.lat() < -90.0) { From bbb23d1b15724c0a3e3daa37d28f3603af2f68da Mon Sep 17 00:00:00 2001 From: Christos Soulios Date: Wed, 27 Nov 2019 17:07:25 +0200 Subject: [PATCH 2/3] Added unit test --- .../mapper/GeoPointFieldMapperTests.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index bf6838ec7b67a..5379557e18b18 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -41,6 +41,7 @@ import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.geometry.utils.Geohash.stringEncode; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_MALFORMED; import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_VALUE; import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.NULL_VALUE; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; @@ -427,6 +428,33 @@ public void testNullValue() throws Exception { assertThat(defaultValue, not(equalTo(doc.rootDoc().getField("location").binaryValue()))); } + /** + * Test the fix for a bug that would read the value of field "ignore_z_value" for "ignore_malformed" + * when setting the "null_value" field. See PR https://github.com/elastic/elasticsearch/pull/49645 + * @throws Exception + */ + public void testNullValueWithIgnoreMalformed() throws Exception { + // Set ignore_z_value = false and ignore_malformed = true and test that a malformed point for null_value is normalized. + String mapping = Strings.toString(XContentFactory.jsonBuilder() + .startObject().startObject("type") + .startObject("properties").startObject("location") + .field("type", "geo_point") + .field(IGNORE_Z_VALUE.getPreferredName(), false) + .field(IGNORE_MALFORMED, true) + .field(NULL_VALUE, "91,181") + .endObject().endObject() + .endObject().endObject()); + + DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + .parse("type", new CompressedXContent(mapping)); + Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); + assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class)); + + Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue(); + // geo_point [91, 181] should have been normalized to [89, 1] + assertThat(nullValue, equalTo(new GeoPoint(89, 1))); + } + public void testInvalidGeohashIgnored() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") From b164a0dfe6cd94980ee892a589908a667c14722d Mon Sep 17 00:00:00 2001 From: Christos Soulios Date: Wed, 27 Nov 2019 17:48:02 +0200 Subject: [PATCH 3/3] Fixed Javadoc error --- .../org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index 5379557e18b18..3ff6eda1fd7fa 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -431,7 +431,6 @@ public void testNullValue() throws Exception { /** * Test the fix for a bug that would read the value of field "ignore_z_value" for "ignore_malformed" * when setting the "null_value" field. See PR https://github.com/elastic/elasticsearch/pull/49645 - * @throws Exception */ public void testNullValueWithIgnoreMalformed() throws Exception { // Set ignore_z_value = false and ignore_malformed = true and test that a malformed point for null_value is normalized.