Do not parse numbers as both strings and numbers when not included in `_all`. #20167
We need to get the string representation of numbers in order to include in `_all`. However this has a cost and disabling `_all` is rather common so we should look into skipping it.
This commit is contained in:
parent
4460998ff8
commit
c5f8e1b64d
|
@ -896,6 +896,8 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
|
||||
@Override
|
||||
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
||||
final boolean includeInAll = context.includeInAll(this.includeInAll, this);
|
||||
|
||||
XContentParser parser = context.parser();
|
||||
Object value;
|
||||
Number numericValue = null;
|
||||
|
@ -908,18 +910,20 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
&& parser.textLength() == 0) {
|
||||
value = null;
|
||||
} else {
|
||||
value = parser.textOrNull();
|
||||
if (value != null) {
|
||||
try {
|
||||
numericValue = fieldType().type.parse(parser, coerce.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (ignoreMalformed.value()) {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
numericValue = fieldType().type.parse(parser, coerce.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (ignoreMalformed.value()) {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (includeInAll) {
|
||||
value = parser.textOrNull(); // preserve formatting
|
||||
} else {
|
||||
value = numericValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
|
@ -934,7 +938,7 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
numericValue = fieldType().type.parse(value);
|
||||
}
|
||||
|
||||
if (context.includeInAll(includeInAll, this)) {
|
||||
if (includeInAll) {
|
||||
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
||||
}
|
||||
|
||||
|
|
|
@ -365,6 +365,8 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
|||
|
||||
@Override
|
||||
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
||||
final boolean includeInAll = context.includeInAll(this.includeInAll, this);
|
||||
|
||||
XContentParser parser = context.parser();
|
||||
Object value;
|
||||
Number numericValue = null;
|
||||
|
@ -377,18 +379,20 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
|||
&& parser.textLength() == 0) {
|
||||
value = null;
|
||||
} else {
|
||||
value = parser.textOrNull();
|
||||
if (value != null) {
|
||||
try {
|
||||
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(parser, coerce.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (ignoreMalformed.value()) {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(parser, coerce.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (ignoreMalformed.value()) {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (includeInAll) {
|
||||
value = parser.textOrNull(); // preserve formatting
|
||||
} else {
|
||||
value = numericValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
|
@ -403,7 +407,7 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
|||
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(value);
|
||||
}
|
||||
|
||||
if (context.includeInAll(includeInAll, this)) {
|
||||
if (includeInAll) {
|
||||
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue