From f582212c68d62dd8c7f16ee0186885ad296f639e Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Fri, 4 Apr 2014 17:52:31 +1100 Subject: [PATCH] `geo_point` doesn't allow null values After upgrading to 1.1.0, sending null values to geo points produces the following error: ``` MapperParsingException[failed to parse]; nested: ElasticsearchParseException[geo_point expected]; ``` Closes #5680. Closes #5681. --- .../index/mapper/geo/GeoPointFieldMapper.java | 2 +- .../mapper/geo/GeohashMappingGeoPointTests.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java index 765bb8d8f54..a0c4f0c0b22 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -525,7 +525,7 @@ public class GeoPointFieldMapper extends AbstractFieldMapper implement } } else if (token == XContentParser.Token.VALUE_STRING) { parsePointFromString(context, sparse, context.parser().text()); - } else { + } else if (token != XContentParser.Token.VALUE_NULL) { parse(context, GeoUtils.parseGeoPoint(context.parser(), sparse), null); } } diff --git a/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java b/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java index ffa8900dde4..3aa9823cb04 100644 --- a/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java @@ -117,4 +117,21 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase { GeoPointFieldMapper geoPointFieldMapper = (GeoPointFieldMapper) mapper; assertThat(geoPointFieldMapper.geoHashPrecision(), is(10)); } + + @Test + public void testNullValue() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("point").field("type", "geo_point").endObject().endObject() + .endObject().endObject().string(); + + DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping); + + ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() + .startObject() + .field("point", (Object) null) + .endObject() + .bytes()); + + assertThat(doc.rootDoc().get("point"), nullValue()); + } }