diff --git a/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java b/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java index a51465c9bd8..579c070785e 100644 --- a/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java +++ b/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java @@ -272,7 +272,7 @@ public class TransportMoreLikeThisAction extends TransportAction { */ T value(Object value); - T valueFromString(String value); - /** * Returns the value that will be used as a result for search. Can be only of specific types... . */ Object valueForSearch(Object value); - /** - * Returns the actual value of the field as string. - */ - String valueAsString(Object value); - /** * Returns the indexed value. */ diff --git a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java index 25cc7385562..ccd079b2d86 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -379,7 +379,7 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { @Override public Object valueForSearch(Object value) { - return valueAsString(value); + return value; } @Override @@ -387,11 +387,6 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { return new BytesRef(value); } - @Override - public String valueAsString(Object value) { - return String.valueOf(value); - } - @Override public Query queryStringTermQuery(Term term) { return null; diff --git a/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java index bb0d8b1873c..9f53b55327a 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java @@ -21,10 +21,12 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Base64; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressorFactory; import org.elasticsearch.common.io.stream.CachedStreamOutput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -139,28 +141,28 @@ public class BinaryFieldMapper extends AbstractFieldMapper { if (value == null) { return null; } + + BytesReference bytes; + if (value instanceof BytesRef) { + bytes = new BytesArray((BytesRef) value); + } else if (value instanceof BytesReference) { + bytes = (BytesReference) value; + } else if (value instanceof byte[]) { + bytes = new BytesArray((byte[]) value); + } else { + try { + bytes = new BytesArray(Base64.decode(value.toString())); + } catch (IOException e) { + throw new ElasticSearchParseException("failed to convert bytes", e); + } + } try { - return CompressorFactory.uncompressIfNeeded(new BytesArray((byte[]) value)).toBytes(); + return CompressorFactory.uncompressIfNeeded(bytes).toBytes(); } catch (IOException e) { throw new ElasticSearchParseException("failed to decompress source", e); } } - @Override - public byte[] valueFromString(String value) { - // assume its base64 (json) - try { - return Base64.decode(value); - } catch (Exception e) { - return null; - } - } - - @Override - public String valueAsString(Object value) { - return null; - } - @Override protected Field parseCreateField(ParseContext context) throws IOException { if (!fieldType().stored()) { diff --git a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java index a0563c86db6..cf4828e7efd 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -166,17 +166,25 @@ public class BooleanFieldMapper extends AbstractFieldMapper { @Override public Boolean value(Object value) { - return valueFromString((String) value); + if (value == null) { + return Boolean.FALSE; + } + String sValue = value.toString(); + if (sValue.length() == 0) { + return Boolean.FALSE; + } + if (sValue.length() == 1 && sValue.charAt(0) == 'F') { + return Boolean.FALSE; + } + if (Booleans.parseBoolean(sValue, false)) { + return Boolean.TRUE; + } + return Boolean.FALSE; } @Override - public Boolean valueFromString(String value) { - return value.charAt(0) == 'T' ? Boolean.TRUE : Boolean.FALSE; - } - - @Override - public String valueAsString(Object value) { - return ((String) value).charAt(0) == 'T' ? "true" : "false"; + public Object valueForSearch(Object value) { + return value(value); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java index b8f8162d7c4..76e4a504fc8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java @@ -32,7 +32,6 @@ import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -141,13 +140,10 @@ public class ByteFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).byteValue(); } - BytesReference bytesReference = (BytesReference) value; - return bytesReference.get(bytesReference.arrayOffset()); - } - - @Override - public Byte valueFromString(String value) { - return Byte.valueOf(value); + if (value instanceof BytesRef) { + return ((BytesRef) value).bytes[((BytesRef) value).offset]; + } + return Byte.parseByte(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java index 645a3a4ac9b..e1372f2e457 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; @@ -197,26 +196,17 @@ public class DateFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).longValue(); } - return Numbers.bytesToLong(((BytesReference) value).array()); - } - - @Override - public Long valueFromString(String value) { - return parseStringValue(value); + if (value instanceof BytesRef) { + return Numbers.bytesToLong((BytesRef) value); + } + return parseStringValue(value.toString()); } /** * Dates should return as a string. - * - * @param value */ @Override public Object valueForSearch(Object value) { - return valueAsString(value); - } - - @Override - public String valueAsString(Object value) { Long val = value(value); if (val == null) { return null; diff --git a/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java index 6db523fdde1..b8eb77af69d 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java @@ -32,7 +32,6 @@ import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -144,12 +143,10 @@ public class DoubleFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).doubleValue(); } - return Numbers.bytesToDouble(((BytesReference) value).array()); - } - - @Override - public Double valueFromString(String value) { - return Double.valueOf(value); + if (value instanceof BytesRef) { + return Numbers.bytesToDouble((BytesRef) value); + } + return Double.parseDouble(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java index 6ffd7a0d2a9..33bdc4284ab 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -142,12 +141,10 @@ public class FloatFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).floatValue(); } - return Numbers.bytesToFloat(((BytesReference) value).array()); - } - - @Override - public Float valueFromString(String value) { - return Float.parseFloat(value); + if (value instanceof BytesRef) { + return Numbers.bytesToFloat((BytesRef) value); + } + return Float.parseFloat(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java index 300b56ca962..e26b3359382 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -144,12 +143,10 @@ public class IntegerFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).intValue(); } - return Numbers.bytesToInt(((BytesReference) value).array()); - } - - @Override - public Integer valueFromString(String value) { - return Integer.parseInt(value); + if (value instanceof BytesRef) { + return Numbers.bytesToInt((BytesRef) value); + } + return Integer.parseInt(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java index a5d08b60a39..c7ed32a6c0f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -144,12 +143,10 @@ public class LongFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).longValue(); } - return Numbers.bytesToLong(((BytesReference) value).array()); - } - - @Override - public Long valueFromString(String value) { - return Long.valueOf(value); + if (value instanceof BytesRef) { + return Numbers.bytesToLong((BytesRef) value); + } + return Long.parseLong(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java index a5df0c9f947..44ff722ddb2 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java @@ -255,12 +255,6 @@ public abstract class NumberFieldMapper extends AbstractFieldM return value(value); } - @Override - public String valueAsString(Object value) { - Number num = value(value); - return num == null ? null : num.toString(); - } - @Override public void merge(Mapper mergeWith, MergeContext mergeContext) throws MergeMappingException { super.merge(mergeWith, mergeContext); diff --git a/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java index e1e4e918d28..f4268af79f5 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -144,12 +143,10 @@ public class ShortFieldMapper extends NumberFieldMapper { if (value instanceof Number) { return ((Number) value).shortValue(); } - return Numbers.bytesToShort(((BytesReference) value).array()); - } - - @Override - public Short valueFromString(String value) { - return Short.valueOf(value); + if (value instanceof BytesRef) { + return Numbers.bytesToShort((BytesRef) value); + } + return Short.parseShort(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java index 15ff66e8073..f2b5ca8830e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java @@ -226,12 +226,10 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al @Override public String value(Object value) { - return String.valueOf(value); - } - - @Override - public String valueFromString(String value) { - return value; + if (value == null) { + return null; + } + return value.toString(); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java index fb62c106f52..ab62fea7239 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java @@ -185,16 +185,6 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { throw new UnsupportedOperationException("GeoShape fields cannot be converted to String values"); } - @Override - public String valueFromString(String value) { - throw new UnsupportedOperationException("GeoShape fields cannot be converted to String values"); - } - - @Override - public String valueAsString(Object value) { - throw new UnsupportedOperationException("GeoShape fields cannot be converted to String values"); - } - public SpatialStrategy spatialStrategy() { return this.spatialStrategy; } diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java index 3e2eb049068..c8feead6779 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java @@ -230,16 +230,6 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna return null; } - @Override - public Void valueFromString(String value) { - return null; - } - - @Override - public String valueAsString(Object value) { - return null; - } - @Override public Object valueForSearch(Object value) { return null; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java index be61195ec1a..eb5e8a108f9 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java @@ -141,12 +141,13 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern if (value == null) { return null; } - return Numbers.bytesToFloat((byte[]) value); - } - - @Override - public Float valueFromString(String value) { - return Float.parseFloat(value); + if (value instanceof Number) { + return ((Number) value).floatValue(); + } + if (value instanceof BytesRef) { + return Numbers.bytesToFloat((BytesRef) value); + } + return Float.parseFloat(value.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java index 3164220c614..99685ce90ae 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java @@ -140,12 +140,10 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern @Override public String value(Object value) { - return String.valueOf(value); - } - - @Override - public String valueFromString(String value) { - return value; + if (value == null) { + return null; + } + return value.toString(); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java index f48d2ec8b5f..e47dbc69127 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; -import org.apache.lucene.index.Term; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -134,16 +133,10 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int @Override public String value(Object value) { - return String.valueOf(value); - } - - @Override - public String valueFromString(String value) { - return value; - } - - public Term term(String value) { - return names().createIndexNameTerm(value); + if (value == null) { + return null; + } + return value.toString(); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java index 7192b68127c..30af89e3ad3 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -176,25 +176,26 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter @Override public Uid value(Object value) { - return Uid.createUid(String.valueOf(value)); - } - - @Override - public Uid valueFromString(String value) { - return Uid.createUid(value); + if (value == null) { + return null; + } + return Uid.createUid(value.toString()); } @Override public Object valueForSearch(Object value) { - String fieldValue = String.valueOf(value); - if (fieldValue == null) { + if (value == null) { return null; } - int index = fieldValue.indexOf(Uid.DELIMITER); - if (index == -1) { - return fieldValue; + String sValue = value.toString(); + if (sValue == null) { + return null; } - return fieldValue.substring(index + 1); + int index = sValue.indexOf(Uid.DELIMITER); + if (index == -1) { + return sValue; + } + return sValue.substring(index + 1); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java index 68a6dc646d2..25397949353 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java @@ -148,12 +148,10 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I @Override public String value(Object value) { - return String.valueOf(value); - } - - @Override - public String valueFromString(String value) { - return value; + if (value == null) { + return null; + } + return value.toString(); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java index 1c89c1a8502..21d7d1ae19c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java @@ -20,13 +20,14 @@ package org.elasticsearch.index.mapper.internal; import com.google.common.base.Objects; -import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.compress.CompressedStreamInput; @@ -346,38 +347,24 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In return new StoredField(names().indexName(), source.array(), source.arrayOffset(), source.length()); } - public byte[] value(Document document) { - Field field = (Field) document.getField(names.indexName()); - return field == null ? null : value(field); - } - - public byte[] nativeValue(Field field) { - return field.binaryValue().bytes; - } - @Override public byte[] value(Object value) { - BytesReference val = (BytesReference) value; - if (val == null) { + if (value == null) { return null; } + BytesReference bValue; + if (value instanceof BytesRef) { + bValue = new BytesArray((BytesRef) value); + } else { + bValue = (BytesReference) value; + } try { - return CompressorFactory.uncompressIfNeeded(val).toBytes(); + return CompressorFactory.uncompressIfNeeded(bValue).toBytes(); } catch (IOException e) { throw new ElasticSearchParseException("failed to decompress source", e); } } - @Override - public byte[] valueFromString(String value) { - return null; - } - - @Override - public String valueAsString(Object value) { - throw new UnsupportedOperationException(); - } - @Override protected String contentType() { return CONTENT_TYPE; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java index f0a2b101321..62c4bf64c3e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java @@ -162,23 +162,12 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap /** * Override the default behavior to return a timestamp - * - * @param value */ @Override public Object valueForSearch(Object value) { return value(value); } - @Override - public String valueAsString(Object value) { - Long val = value(value); - if (val == null) { - return null; - } - return val.toString(); - } - @Override public void validate(ParseContext context) throws MapperParsingException { } diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java index 90ba960e68a..ae99001a2db 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java @@ -112,12 +112,10 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte @Override public String value(Object value) { - return String.valueOf(value); - } - - @Override - public String valueFromString(String value) { - return value; + if (value == null) { + return null; + } + return value.toString(); } public Term term(String value) { diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java index a91f7dea525..09de0a8ef19 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -190,12 +190,10 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal @Override public Uid value(Object value) { - return Uid.createUid(String.valueOf(value)); - } - - @Override - public Uid valueFromString(String value) { - return Uid.createUid(value); + if (value == null) { + return null; + } + return Uid.createUid(value.toString()); } public Term term(String type, String id) { diff --git a/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java index 9937111311c..b968897dcbf 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java @@ -163,26 +163,20 @@ public class IpFieldMapper extends NumberFieldMapper { if (value == null) { return null; } - return Numbers.bytesToLong((byte[]) value); - } - - @Override - public Long valueFromString(String value) { - return ipToLong(value); + if (value instanceof Number) { + return ((Number) value).longValue(); + } + if (value instanceof BytesRef) { + return Numbers.bytesToLong((BytesRef) value); + } + return ipToLong(value.toString()); } /** * IPs should return as a string. - * - * @param value */ @Override public Object valueForSearch(Object value) { - return valueAsString(value); - } - - @Override - public String valueAsString(Object value) { Long val = value(value); if (val == null) { return null; diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacetProcessor.java b/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacetProcessor.java index e1060c261e0..51e51ba3cec 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacetProcessor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacetProcessor.java @@ -120,8 +120,8 @@ public class HistogramFacetProcessor extends AbstractComponent implements FacetP if (mapper == null) { throw new FacetPhaseExecutionException(facetName, "No mapping found for key_field [" + keyField + "]"); } - long from = ((Number) mapper.valueFromString(sFrom)).longValue(); - long to = ((Number) mapper.valueFromString(sTo)).longValue(); + long from = ((Number) mapper.value(sFrom)).longValue(); + long to = ((Number) mapper.value(sTo)).longValue(); if (valueField != null) { return new BoundedValueHistogramFacetCollector(facetName, keyField, valueField, interval, from, to, comparatorType, context); diff --git a/src/main/java/org/elasticsearch/search/facet/range/RangeFacetProcessor.java b/src/main/java/org/elasticsearch/search/facet/range/RangeFacetProcessor.java index e7cd3ad86b3..34b82de09da 100644 --- a/src/main/java/org/elasticsearch/search/facet/range/RangeFacetProcessor.java +++ b/src/main/java/org/elasticsearch/search/facet/range/RangeFacetProcessor.java @@ -127,10 +127,10 @@ public class RangeFacetProcessor extends AbstractComponent implements FacetProce } for (RangeFacet.Entry entry : rangeEntries) { if (entry.fromAsString != null) { - entry.from = ((Number) mapper.valueFromString(entry.fromAsString)).doubleValue(); + entry.from = ((Number) mapper.value(entry.fromAsString)).doubleValue(); } if (entry.toAsString != null) { - entry.to = ((Number) mapper.valueFromString(entry.toAsString)).doubleValue(); + entry.to = ((Number) mapper.value(entry.toAsString)).doubleValue(); } } } diff --git a/src/test/java/org/elasticsearch/test/integration/search/fields/SearchFieldsTests.java b/src/test/java/org/elasticsearch/test/integration/search/fields/SearchFieldsTests.java index 60e816b039a..7347986ffe7 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/fields/SearchFieldsTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/fields/SearchFieldsTests.java @@ -342,7 +342,7 @@ public class SearchFieldsTests extends AbstractNodesTests { assertThat(searchResponse.hits().getAt(0).fields().get("double_field").value(), equalTo((Object) 6.0d)); String dateTime = Joda.forPattern("dateOptionalTime").printer().print(new DateTime(2012, 3, 22, 0, 0, DateTimeZone.UTC)); assertThat(searchResponse.hits().getAt(0).fields().get("date_field").value(), equalTo((Object) dateTime)); - assertThat(searchResponse.hits().getAt(0).fields().get("boolean_field").value(), equalTo((Object) "true")); + assertThat(searchResponse.hits().getAt(0).fields().get("boolean_field").value(), equalTo((Object) Boolean.TRUE)); assertThat(searchResponse.hits().getAt(0).fields().get("binary_field").value().toString(), equalTo(Base64.encodeBytes("testing text".getBytes("UTF8")))); }