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
|
@Override
|
||||||
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
||||||
|
final boolean includeInAll = context.includeInAll(this.includeInAll, this);
|
||||||
|
|
||||||
XContentParser parser = context.parser();
|
XContentParser parser = context.parser();
|
||||||
Object value;
|
Object value;
|
||||||
Number numericValue = null;
|
Number numericValue = null;
|
||||||
|
@ -908,8 +910,6 @@ public class NumberFieldMapper extends FieldMapper {
|
||||||
&& parser.textLength() == 0) {
|
&& parser.textLength() == 0) {
|
||||||
value = null;
|
value = null;
|
||||||
} else {
|
} else {
|
||||||
value = parser.textOrNull();
|
|
||||||
if (value != null) {
|
|
||||||
try {
|
try {
|
||||||
numericValue = fieldType().type.parse(parser, coerce.value());
|
numericValue = fieldType().type.parse(parser, coerce.value());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -919,6 +919,10 @@ public class NumberFieldMapper extends FieldMapper {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (includeInAll) {
|
||||||
|
value = parser.textOrNull(); // preserve formatting
|
||||||
|
} else {
|
||||||
|
value = numericValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,7 +938,7 @@ public class NumberFieldMapper extends FieldMapper {
|
||||||
numericValue = fieldType().type.parse(value);
|
numericValue = fieldType().type.parse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.includeInAll(includeInAll, this)) {
|
if (includeInAll) {
|
||||||
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -365,6 +365,8 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
|
||||||
|
final boolean includeInAll = context.includeInAll(this.includeInAll, this);
|
||||||
|
|
||||||
XContentParser parser = context.parser();
|
XContentParser parser = context.parser();
|
||||||
Object value;
|
Object value;
|
||||||
Number numericValue = null;
|
Number numericValue = null;
|
||||||
|
@ -377,8 +379,6 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||||
&& parser.textLength() == 0) {
|
&& parser.textLength() == 0) {
|
||||||
value = null;
|
value = null;
|
||||||
} else {
|
} else {
|
||||||
value = parser.textOrNull();
|
|
||||||
if (value != null) {
|
|
||||||
try {
|
try {
|
||||||
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(parser, coerce.value());
|
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(parser, coerce.value());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -388,6 +388,10 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (includeInAll) {
|
||||||
|
value = parser.textOrNull(); // preserve formatting
|
||||||
|
} else {
|
||||||
|
value = numericValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +407,7 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||||
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(value);
|
numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.includeInAll(includeInAll, this)) {
|
if (includeInAll) {
|
||||||
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue