Currently when adding a document with a `null` value for a range field, the range field mapper raises an error. Instead we should ignore null like we do eg. with numbers or geo points. Closes #27845
This commit is contained in:
parent
caa63ada6b
commit
6c963379d9
|
@ -357,7 +357,9 @@ public class RangeFieldMapper extends FieldMapper {
|
||||||
} else {
|
} else {
|
||||||
XContentParser parser = context.parser();
|
XContentParser parser = context.parser();
|
||||||
final XContentParser.Token start = parser.currentToken();
|
final XContentParser.Token start = parser.currentToken();
|
||||||
if (start == XContentParser.Token.START_OBJECT) {
|
if (start == XContentParser.Token.VALUE_NULL) {
|
||||||
|
return;
|
||||||
|
} else if (start == XContentParser.Token.START_OBJECT) {
|
||||||
RangeFieldType fieldType = fieldType();
|
RangeFieldType fieldType = fieldType();
|
||||||
RangeType rangeType = fieldType.rangeType;
|
RangeType rangeType = fieldType.rangeType;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
|
|
|
@ -363,6 +363,15 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
||||||
+ InetAddresses.toAddrString(InetAddresses.forString("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
|
+ InetAddresses.toAddrString(InetAddresses.forString("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
|
||||||
}
|
}
|
||||||
assertThat(storedField.stringValue(), containsString(strVal));
|
assertThat(storedField.stringValue(), containsString(strVal));
|
||||||
|
|
||||||
|
// test null range
|
||||||
|
doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder()
|
||||||
|
.startObject()
|
||||||
|
.nullField("field")
|
||||||
|
.endObject()
|
||||||
|
.bytes(),
|
||||||
|
XContentType.JSON));
|
||||||
|
assertNull(doc.rootDoc().get("field"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoBounds() throws Exception {
|
public void testNoBounds() throws Exception {
|
||||||
|
|
|
@ -45,6 +45,12 @@ setup:
|
||||||
id: 3
|
id: 3
|
||||||
body: { "integer_range" : { "gte": 4, "lte": 5 } }
|
body: { "integer_range" : { "gte": 4, "lte": 5 } }
|
||||||
|
|
||||||
|
- do:
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
type: doc
|
||||||
|
id: 4
|
||||||
|
body: { "integer_range" : null }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
indices.refresh: {}
|
indices.refresh: {}
|
||||||
|
@ -79,6 +85,12 @@ setup:
|
||||||
|
|
||||||
- match: { hits.total: 0 }
|
- match: { hits.total: 0 }
|
||||||
|
|
||||||
|
- do:
|
||||||
|
search:
|
||||||
|
body: { "query" : { "match_all": {} } }
|
||||||
|
|
||||||
|
- match: { hits.total: 4 }
|
||||||
|
|
||||||
---
|
---
|
||||||
"Long range":
|
"Long range":
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue