Skip to content

Commit 4b16d50

Browse files
authored
Fix typo when assigning null_value in GeoPointFieldMapper (#49645)
This PR fixes a trivial typo error that affects assigning null_value in the GeoPointFieldMapper
1 parent 7a7d15b commit 4b16d50

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
160160

161161
if (nullValue != null) {
162162
boolean ignoreZValue = builder.ignoreZValue == null ? Defaults.IGNORE_Z_VALUE.value() : builder.ignoreZValue;
163-
boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreZValue;
163+
boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreMalformed;
164164
GeoPoint point = GeoUtils.parseGeoPoint(nullValue, ignoreZValue);
165165
if (ignoreMalformed == false) {
166166
if (point.lat() > 90.0 || point.lat() < -90.0) {

server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java

+27
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
4242
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
4343
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
44+
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_MALFORMED;
4445
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_VALUE;
4546
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.NULL_VALUE;
4647
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
@@ -427,6 +428,32 @@ public void testNullValue() throws Exception {
427428
assertThat(defaultValue, not(equalTo(doc.rootDoc().getField("location").binaryValue())));
428429
}
429430

431+
/**
432+
* Test the fix for a bug that would read the value of field "ignore_z_value" for "ignore_malformed"
433+
* when setting the "null_value" field. See PR https://github.com/elastic/elasticsearch/pull/49645
434+
*/
435+
public void testNullValueWithIgnoreMalformed() throws Exception {
436+
// Set ignore_z_value = false and ignore_malformed = true and test that a malformed point for null_value is normalized.
437+
String mapping = Strings.toString(XContentFactory.jsonBuilder()
438+
.startObject().startObject("type")
439+
.startObject("properties").startObject("location")
440+
.field("type", "geo_point")
441+
.field(IGNORE_Z_VALUE.getPreferredName(), false)
442+
.field(IGNORE_MALFORMED, true)
443+
.field(NULL_VALUE, "91,181")
444+
.endObject().endObject()
445+
.endObject().endObject());
446+
447+
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
448+
.parse("type", new CompressedXContent(mapping));
449+
Mapper fieldMapper = defaultMapper.mappers().getMapper("location");
450+
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
451+
452+
Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue();
453+
// geo_point [91, 181] should have been normalized to [89, 1]
454+
assertThat(nullValue, equalTo(new GeoPoint(89, 1)));
455+
}
456+
430457
public void testInvalidGeohashIgnored() throws Exception {
431458
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
432459
.startObject("properties")

0 commit comments

Comments
 (0)