Fix handling of null values in geo_point (#65307)

A bug was introduced in 7.10 that causes explicit `null` values to be indexed in the _field_names
field. This change fixes this bug for newly ingested data but `null` values ingested with 7.10 will
continue to match `exists` query so a reindex is required.

Fixes #65306
This commit is contained in:
Jim Ferenczi 2020-11-24 10:22:41 +01:00 committed by jimczi
parent 59ceba8d04
commit 88993e763f
2 changed files with 26 additions and 5 deletions

View File

@ -235,9 +235,8 @@ public abstract class AbstractPointGeometryFieldMapper<Parsed, Processed> extend
return points;
} else if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
if (nullValue == null) {
return Collections.emptyList();
}
else {
return null;
} else {
return Collections.singletonList(nullValue);
}
} else {

View File

@ -232,14 +232,36 @@ public class GeoPointFieldMapperTests extends FieldMapperTestCase2<GeoPointField
}
public void testNullValue() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_point").field("null_value", "1,2")));
DocumentMapper mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "geo_point"))
);
Mapper fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
ParsedDocument doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), nullValue());
assertThat(doc.rootDoc().getFields(FieldNamesFieldMapper.NAME).length, equalTo(0));
mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "geo_point").field("doc_values", false))
);
fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), nullValue());
assertThat(doc.rootDoc().getFields(FieldNamesFieldMapper.NAME).length, equalTo(0));
mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "geo_point").field("null_value", "1,2"))
);
fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
AbstractPointGeometryFieldMapper.ParsedPoint nullValue = ((GeoPointFieldMapper) fieldMapper).nullValue;
assertThat(nullValue, equalTo(new GeoPoint(1, 2)));
ParsedDocument doc = mapper.parse(source(b -> b.nullField("field")));
doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), notNullValue());
BytesRef defaultValue = doc.rootDoc().getBinaryValue("field");