diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java index 34ed79984df96..9118aa9478937 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java @@ -213,6 +213,9 @@ public FieldDataType defaultFieldDataType() { public void parse(ParseContext context) throws IOException { try { ShapeBuilder shape = ShapeBuilder.parse(context.parser()); + if(shape == null) { + return; + } Field[] fields = defaultStrategy.createIndexableFields(shape.build()); if (fields == null || fields.length == 0) { return; diff --git a/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java b/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java index 8186bf945f4e8..a5a0090677b54 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java @@ -21,18 +21,16 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.geoIntersectionFilter; -import static org.elasticsearch.index.query.QueryBuilders.filteredQuery; -import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.*; import java.io.IOException; import java.util.List; import java.util.Map; +import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -43,6 +41,21 @@ public class GeoShapeIntegrationTests extends AbstractSharedClusterTest { + @Test + public void testNullShape() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1") + .startObject("properties").startObject("location") + .field("type", "geo_shape") + .endObject().endObject() + .endObject().endObject().string(); + prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + ensureGreen(); + + client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}").execute().actionGet(); + GetResponse result = client().prepareGet("test", "type1", "aNullshape").execute().actionGet(); + assertThat(result.getField("location"), nullValue()); + } + @Test public void testIndexPointsFilterRectangle() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")