Skip to content

Commit

Permalink
Fix typo when assigning null_value in GeoPointFieldMapper (#49645)
Browse files Browse the repository at this point in the history
This PR fixes a trivial typo error that affects assigning null_value in the GeoPointFieldMapper
  • Loading branch information
csoulios authored Nov 27, 2019
1 parent 7a7d15b commit 4b16d50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext

if (nullValue != null) {
boolean ignoreZValue = builder.ignoreZValue == null ? Defaults.IGNORE_Z_VALUE.value() : builder.ignoreZValue;
boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreZValue;
boolean ignoreMalformed = builder.ignoreMalformed == null ? Defaults.IGNORE_MALFORMED.value() : builder.ignoreMalformed;
GeoPoint point = GeoUtils.parseGeoPoint(nullValue, ignoreZValue);
if (ignoreMalformed == false) {
if (point.lat() > 90.0 || point.lat() < -90.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_MALFORMED;
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_VALUE;
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.NULL_VALUE;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
Expand Down Expand Up @@ -427,6 +428,32 @@ public void testNullValue() throws Exception {
assertThat(defaultValue, not(equalTo(doc.rootDoc().getField("location").binaryValue())));
}

/**
* Test the fix for a bug that would read the value of field "ignore_z_value" for "ignore_malformed"
* when setting the "null_value" field. See PR https://github.com/elastic/elasticsearch/pull/49645
*/
public void testNullValueWithIgnoreMalformed() throws Exception {
// Set ignore_z_value = false and ignore_malformed = true and test that a malformed point for null_value is normalized.
String mapping = Strings.toString(XContentFactory.jsonBuilder()
.startObject().startObject("type")
.startObject("properties").startObject("location")
.field("type", "geo_point")
.field(IGNORE_Z_VALUE.getPreferredName(), false)
.field(IGNORE_MALFORMED, true)
.field(NULL_VALUE, "91,181")
.endObject().endObject()
.endObject().endObject());

DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("location");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));

Object nullValue = ((GeoPointFieldMapper) fieldMapper).fieldType().nullValue();
// geo_point [91, 181] should have been normalized to [89, 1]
assertThat(nullValue, equalTo(new GeoPoint(89, 1)));
}

public void testInvalidGeohashIgnored() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
Expand Down

0 comments on commit 4b16d50

Please sign in to comment.