diff --git a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index be6ed23c508..886b93fcf0e 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -896,6 +896,8 @@ public class NumberFieldMapper extends FieldMapper { @Override protected void parseCreateField(ParseContext context, List 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()); } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index b7276e4e114..bcad6aa063e 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -365,6 +365,8 @@ public class ScaledFloatFieldMapper extends FieldMapper { @Override protected void parseCreateField(ParseContext context, List 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()); }