Skip to content

Commit 6e9ad03

Browse files
committed
Fixed nullshape indexing.
Closes #3310
1 parent 3087fd8 commit 6e9ad03

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ public FieldDataType defaultFieldDataType() {
213213
public void parse(ParseContext context) throws IOException {
214214
try {
215215
ShapeBuilder shape = ShapeBuilder.parse(context.parser());
216+
if(shape == null) {
217+
return;
218+
}
216219
Field[] fields = defaultStrategy.createIndexableFields(shape.build());
217220
if (fields == null || fields.length == 0) {
218221
return;

src/test/java/org/elasticsearch/test/integration/search/geo/GeoShapeIntegrationTests.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121

2222
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
2323
import static org.elasticsearch.index.query.FilterBuilders.geoIntersectionFilter;
24-
import static org.elasticsearch.index.query.QueryBuilders.filteredQuery;
25-
import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery;
26-
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
24+
import static org.elasticsearch.index.query.QueryBuilders.*;
2725
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
2826
import static org.hamcrest.MatcherAssert.assertThat;
29-
import static org.hamcrest.Matchers.equalTo;
30-
import static org.hamcrest.Matchers.instanceOf;
27+
import static org.hamcrest.Matchers.*;
3128

3229
import java.io.IOException;
3330
import java.util.List;
3431
import java.util.Map;
3532

33+
import org.elasticsearch.action.get.GetResponse;
3634
import org.elasticsearch.action.search.SearchResponse;
3735
import org.elasticsearch.common.geo.builders.ShapeBuilder;
3836
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -43,6 +41,21 @@
4341

4442
public class GeoShapeIntegrationTests extends AbstractSharedClusterTest {
4543

44+
@Test
45+
public void testNullShape() throws Exception {
46+
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
47+
.startObject("properties").startObject("location")
48+
.field("type", "geo_shape")
49+
.endObject().endObject()
50+
.endObject().endObject().string();
51+
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
52+
ensureGreen();
53+
54+
client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}").execute().actionGet();
55+
GetResponse result = client().prepareGet("test", "type1", "aNullshape").execute().actionGet();
56+
assertThat(result.getField("location"), nullValue());
57+
}
58+
4659
@Test
4760
public void testIndexPointsFilterRectangle() throws Exception {
4861
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")

0 commit comments

Comments
 (0)