|
41 | 41 | import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
42 | 42 | import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
43 | 43 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
| 44 | +import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_MALFORMED; |
44 | 45 | import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_VALUE;
|
45 | 46 | import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.NULL_VALUE;
|
46 | 47 | import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
@@ -427,6 +428,32 @@ public void testNullValue() throws Exception {
|
427 | 428 | assertThat(defaultValue, not(equalTo(doc.rootDoc().getField("location").binaryValue())));
|
428 | 429 | }
|
429 | 430 |
|
| 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 | + |
430 | 457 | public void testInvalidGeohashIgnored() throws Exception {
|
431 | 458 | String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
432 | 459 | .startObject("properties")
|
|
0 commit comments