From 1867ef50845dcc19aac3dd8a6027d44931691326 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 18 Dec 2012 13:00:47 -0800 Subject: [PATCH] simplify toXContent generation of field mappers --- .../common/lucene/uid/UidField.java | 2 +- .../PerFieldMappingPostingFormatCodec.java | 2 +- .../index/mapper/DocumentMapper.java | 3 +- .../index/mapper/FieldMapper.java | 2 +- .../mapper/core/AbstractFieldMapper.java | 88 +++++++++++++------ .../index/mapper/core/BinaryFieldMapper.java | 13 ++- .../index/mapper/core/BooleanFieldMapper.java | 41 ++------- .../index/mapper/core/ByteFieldMapper.java | 39 ++------ .../index/mapper/core/DateFieldMapper.java | 39 ++------ .../index/mapper/core/DoubleFieldMapper.java | 39 ++------ .../index/mapper/core/FloatFieldMapper.java | 39 ++------ .../index/mapper/core/IntegerFieldMapper.java | 39 ++------ .../index/mapper/core/LongFieldMapper.java | 41 ++------- .../index/mapper/core/NumberFieldMapper.java | 12 +-- .../index/mapper/core/ShortFieldMapper.java | 39 ++------ .../index/mapper/core/StringFieldMapper.java | 39 ++------ .../index/mapper/geo/GeoPointFieldMapper.java | 19 ++-- .../index/mapper/geo/GeoShapeFieldMapper.java | 23 +++-- .../index/mapper/internal/AllFieldMapper.java | 31 ++++--- .../mapper/internal/BoostFieldMapper.java | 15 ++-- .../index/mapper/internal/IdFieldMapper.java | 29 +++--- .../mapper/internal/IndexFieldMapper.java | 27 +++--- .../mapper/internal/ParentFieldMapper.java | 21 +++-- .../mapper/internal/RoutingFieldMapper.java | 31 ++++--- .../mapper/internal/SizeFieldMapper.java | 2 +- .../mapper/internal/SourceFieldMapper.java | 19 ++-- .../index/mapper/internal/TTLFieldMapper.java | 2 +- .../mapper/internal/TimestampFieldMapper.java | 27 +++--- .../mapper/internal/TypeFieldMapper.java | 31 ++++--- .../index/mapper/internal/UidFieldMapper.java | 43 +++++++-- .../index/mapper/ip/IpFieldMapper.java | 39 ++------ .../unit/common/lucene/uid/UidFieldTests.java | 2 +- .../test/unit/index/codec/CodecTests.java | 44 +++++----- .../engine/AbstractSimpleEngineTests.java | 6 +- .../timestamp/TimestampMappingTests.java | 4 +- 35 files changed, 388 insertions(+), 504 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java b/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java index ab0194ae29d..40ec2107ab6 100644 --- a/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java +++ b/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java @@ -125,7 +125,7 @@ public class UidField extends Field { } public UidField(String name, String uid, long version) { - super(name, UidFieldMapper.Defaults.UID_FIELD_TYPE); + super(name, UidFieldMapper.Defaults.FIELD_TYPE); this.uid = uid; this.version = version; this.tokenStream = new UidPayloadTokenStream(this); diff --git a/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java b/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java index 0e8db9989a7..07f1e9364b1 100644 --- a/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java +++ b/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java @@ -45,7 +45,7 @@ public class PerFieldMappingPostingFormatCodec extends Lucene40Codec { @Override public PostingsFormat getPostingsFormatForField(String field) { - PostingsFormatProvider postingsFormat = mapperService.indexName(field).mapper().postingFormatProvider(); + PostingsFormatProvider postingsFormat = mapperService.indexName(field).mapper().postingsFormatProvider(); return postingsFormat != null ? postingsFormat.get() : defaultPostingFormat; } } diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index b08917ca067..35dd501a2bc 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -154,7 +154,7 @@ public class DocumentMapper implements ToXContent { if (indexSettings != null) { String idIndexed = indexSettings.get("index.mapping._id.indexed"); if (idIndexed != null && Booleans.parseBoolean(idIndexed, false)) { - FieldType fieldType = new FieldType(IdFieldMapper.Defaults.ID_FIELD_TYPE); + FieldType fieldType = new FieldType(IdFieldMapper.Defaults.FIELD_TYPE); fieldType.setTokenized(false); idFieldMapper = new IdFieldMapper(fieldType); } @@ -495,7 +495,6 @@ public class DocumentMapper implements ToXContent { } // fire up any new mappers if exists - // we do it here so postParse can rely on having them as part of this doc mapper if (!context.newFieldMappers().mappers.isEmpty()) { addFieldMappers(context.newFieldMappers().mappers); } diff --git a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index 645ddab78b5..19107cf716b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -230,6 +230,6 @@ public interface FieldMapper { FieldDataType fieldDataType(); - PostingsFormatProvider postingFormatProvider(); + PostingsFormatProvider postingsFormatProvider(); } 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 7f3d064bcd8..08c42755571 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -308,6 +308,8 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { return this.names; } + public abstract FieldType defaultFieldType(); + @Override public boolean stored() { return fieldType.stored(); @@ -589,7 +591,7 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { } @Override - public PostingsFormatProvider postingFormatProvider() { + public PostingsFormatProvider postingsFormatProvider() { return postingsFormat; } @@ -601,6 +603,65 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { return builder; } + protected void doXContentBody(XContentBuilder builder) throws IOException { + builder.field("type", contentType()); + if (!names.name().equals(names.indexNameClean())) { + builder.field("index_name", names.indexNameClean()); + } + + if (boost != 1.0f) { + builder.field("boost", boost); + } + + FieldType defaultFieldType = defaultFieldType(); + if (indexed() != defaultFieldType.indexed() || + tokenized() != defaultFieldType.tokenized()) { + builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); + } + if (stored() != defaultFieldType.stored()) { + builder.field("store", stored()); + } + if (storeTermVectors() != defaultFieldType.storeTermVectors()) { + builder.field("store_term_vector", storeTermVectors()); + } + if (storeTermVectorOffsets() != defaultFieldType.storeTermVectorOffsets()) { + builder.field("store_term_vector_offsets", storeTermVectorOffsets()); + } + if (storeTermVectorPositions() != defaultFieldType.storeTermVectorPositions()) { + builder.field("store_term_vector_positions", storeTermVectorPositions()); + } + if (storeTermVectorPayloads() != defaultFieldType.storeTermVectorPayloads()) { + builder.field("store_term_vector_payloads", storeTermVectorPayloads()); + } + if (omitNorms() != defaultFieldType.omitNorms()) { + builder.field("omit_norms", omitNorms()); + } + if (indexOptions() != defaultFieldType.indexOptions()) { + builder.field("index_options", indexOptionToString(indexOptions())); + } + + if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_") && !indexAnalyzer.name().equals("default")) { + // same analyzers, output it once + builder.field("analyzer", indexAnalyzer.name()); + } else { + if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_") && !indexAnalyzer.name().equals("default")) { + builder.field("index_analyzer", indexAnalyzer.name()); + } + if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_") && !searchAnalyzer.name().equals("default")) { + builder.field("search_analyzer", searchAnalyzer.name()); + } + } + if (postingsFormat != null) { + if (!postingsFormat.name().equals(defaultPostingFormat())) { + builder.field("postings_format", postingsFormat.name()); + } + } + + if (similarity() != null) { + builder.field("similarity", similarity().name()); + } + } + protected static String indexOptionToString(IndexOptions indexOption) { switch (indexOption) { case DOCS_AND_FREQS: @@ -624,31 +685,6 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { } } - protected void doXContentBody(XContentBuilder builder) throws IOException { - builder.field("type", contentType()); - if (!names.name().equals(names.indexNameClean())) { - builder.field("index_name", names.indexNameClean()); - } - if (boost != 1.0f) { - builder.field("boost", boost); - } - if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_") && !indexAnalyzer.name().equals("default")) { - // same analyzers, output it once - builder.field("analyzer", indexAnalyzer.name()); - } else { - if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_") && !indexAnalyzer.name().equals("default")) { - builder.field("index_analyzer", indexAnalyzer.name()); - } - if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_") && !searchAnalyzer.name().equals("default")) { - builder.field("search_analyzer", searchAnalyzer.name()); - } - } - if (postingsFormat != null) { - if (!postingsFormat.name().equals(defaultPostingFormat())) { - builder.field("postings_format", postingsFormat.name()); - } - } - } protected abstract String contentType(); 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 49e760f4cb4..dfaff23cebb 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java @@ -50,11 +50,11 @@ public class BinaryFieldMapper extends AbstractFieldMapper { public static class Defaults extends AbstractFieldMapper.Defaults { public static final long COMPRESS_THRESHOLD = -1; - public static final FieldType BINARY_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - BINARY_FIELD_TYPE.setStored(false); - BINARY_FIELD_TYPE.freeze(); + FIELD_TYPE.setStored(false); + FIELD_TYPE.freeze(); } } @@ -65,7 +65,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper { private long compressThreshold = Defaults.COMPRESS_THRESHOLD; public Builder(String name) { - super(name, new FieldType(Defaults.BINARY_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -124,6 +124,11 @@ public class BinaryFieldMapper extends AbstractFieldMapper { this.compressThreshold = compressThreshold; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public Object valueForSearch(Object value) { return value(value); 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 3ca0dddf63b..f5ed1a5c886 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -51,11 +51,11 @@ public class BooleanFieldMapper extends AbstractFieldMapper { public static final String CONTENT_TYPE = "boolean"; public static class Defaults extends AbstractFieldMapper.Defaults { - public static final FieldType BOOLEAN_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - BOOLEAN_FIELD_TYPE.setOmitNorms(true); - BOOLEAN_FIELD_TYPE.freeze(); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.freeze(); } public static final Boolean NULL_VALUE = null; @@ -71,7 +71,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper { private Boolean nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.BOOLEAN_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); this.builder = this; } @@ -154,6 +154,11 @@ public class BooleanFieldMapper extends AbstractFieldMapper { this.nullValue = nullValue; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public boolean useFieldQueryWithQueryString() { return true; @@ -224,34 +229,6 @@ public class BooleanFieldMapper extends AbstractFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.BOOLEAN_FIELD_TYPE.indexed() || - tokenized() != Defaults.BOOLEAN_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.BOOLEAN_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.BOOLEAN_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.BOOLEAN_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 c5f03bac068..46dce99fb28 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java @@ -60,10 +60,10 @@ public class ByteFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "byte"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType BYTE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - BYTE_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Byte NULL_VALUE = null; @@ -74,7 +74,7 @@ public class ByteFieldMapper extends NumberFieldMapper { protected Byte nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.BYTE_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -123,6 +123,11 @@ public class ByteFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 32; @@ -328,40 +333,12 @@ public class ByteFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.BYTE_FIELD_TYPE.indexed() || - tokenized() != Defaults.BYTE_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.BYTE_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.BYTE_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.BYTE_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.BYTE_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.BYTE_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.BYTE_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.BYTE_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 6b8f3a96665..91dd7db3669 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java @@ -66,10 +66,10 @@ public class DateFieldMapper extends NumberFieldMapper { public static class Defaults extends NumberFieldMapper.Defaults { public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("dateOptionalTime"); - public static final FieldType DATE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - DATE_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final String NULL_VALUE = null; @@ -87,7 +87,7 @@ public class DateFieldMapper extends NumberFieldMapper { protected FormatDateTimeFormatter dateTimeFormatter = Defaults.DATE_TIME_FORMATTER; public Builder(String name) { - super(name, new FieldType(Defaults.DATE_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -167,6 +167,11 @@ public class DateFieldMapper extends NumberFieldMapper { this.dateMathParser = new DateMathParser(dateTimeFormatter, timeUnit); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected double parseFuzzyFactor(String fuzzyFactor) { if (fuzzyFactor == null) { @@ -402,31 +407,6 @@ public class DateFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.DATE_FIELD_TYPE.indexed() || - tokenized() != Defaults.DATE_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.DATE_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.DATE_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.DATE_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.DATE_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.DATE_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.DATE_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.DATE_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } @@ -434,9 +414,6 @@ public class DateFieldMapper extends NumberFieldMapper { builder.field("fuzzy_factor", fuzzyFactor); } builder.field("format", dateTimeFormatter.format()); - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 eade787e911..9a0aeb1dcdd 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java @@ -60,10 +60,10 @@ public class DoubleFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "double"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType DOUBLE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - DOUBLE_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Double NULL_VALUE = null; @@ -74,7 +74,7 @@ public class DoubleFieldMapper extends NumberFieldMapper { protected Double nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.DOUBLE_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -126,6 +126,11 @@ public class DoubleFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 64; @@ -331,40 +336,12 @@ public class DoubleFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.DOUBLE_FIELD_TYPE.indexed() || - tokenized() != Defaults.DOUBLE_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.DOUBLE_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.DOUBLE_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.DOUBLE_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 43cc3aa63c8..d3ca9e6cdbc 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java @@ -61,10 +61,10 @@ public class FloatFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "float"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType FLOAT_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - FLOAT_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Float NULL_VALUE = null; @@ -75,7 +75,7 @@ public class FloatFieldMapper extends NumberFieldMapper { protected Float nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.FLOAT_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -124,6 +124,11 @@ public class FloatFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 32; @@ -326,40 +331,12 @@ public class FloatFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.FLOAT_FIELD_TYPE.indexed() || - tokenized() != Defaults.FLOAT_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.FLOAT_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.FLOAT_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.FLOAT_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.FLOAT_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 78d1351066f..bd71232f55e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java @@ -61,10 +61,10 @@ public class IntegerFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "integer"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType INTEGER_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - INTEGER_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Integer NULL_VALUE = null; @@ -75,7 +75,7 @@ public class IntegerFieldMapper extends NumberFieldMapper { protected Integer nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.INTEGER_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -126,6 +126,11 @@ public class IntegerFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 32; @@ -331,40 +336,12 @@ public class IntegerFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.INTEGER_FIELD_TYPE.indexed() || - tokenized() != Defaults.INTEGER_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.INTEGER_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.INTEGER_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.INTEGER_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.INTEGER_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 615c7ad550e..e130cf58bcf 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java @@ -61,10 +61,10 @@ public class LongFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "long"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType LONG_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - LONG_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Long NULL_VALUE = null; @@ -75,7 +75,7 @@ public class LongFieldMapper extends NumberFieldMapper { protected Long nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.LONG_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -86,7 +86,7 @@ public class LongFieldMapper extends NumberFieldMapper { @Override public LongFieldMapper build(BuilderContext context) { - fieldType.setOmitNorms(fieldType.omitNorms() && boost != 1.0f); + fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context), provider, similarity); @@ -126,6 +126,11 @@ public class LongFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 64; @@ -330,40 +335,12 @@ public class LongFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.LONG_FIELD_TYPE.indexed() || - tokenized() != Defaults.LONG_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.LONG_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.LONG_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.LONG_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.LONG_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.LONG_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.LONG_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.LONG_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 c104b3ad178..dd4153e2235 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java @@ -50,14 +50,14 @@ public abstract class NumberFieldMapper extends AbstractFieldM public static class Defaults extends AbstractFieldMapper.Defaults { public static final int PRECISION_STEP = NumericUtils.PRECISION_STEP_DEFAULT; - public static final FieldType NUMBER_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - NUMBER_FIELD_TYPE.setTokenized(false); - NUMBER_FIELD_TYPE.setOmitNorms(true); - NUMBER_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - NUMBER_FIELD_TYPE.setStoreTermVectors(false); - NUMBER_FIELD_TYPE.freeze(); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.setStoreTermVectors(false); + FIELD_TYPE.freeze(); } public static final String FUZZY_FACTOR = null; 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 a495a3ff506..27f1132aadc 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java @@ -61,10 +61,10 @@ public class ShortFieldMapper extends NumberFieldMapper { public static final String CONTENT_TYPE = "short"; public static class Defaults extends NumberFieldMapper.Defaults { - public static final FieldType SHORT_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - SHORT_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } public static final Short NULL_VALUE = null; @@ -75,7 +75,7 @@ public class ShortFieldMapper extends NumberFieldMapper { protected Short nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.SHORT_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -126,6 +126,11 @@ public class ShortFieldMapper extends NumberFieldMapper { this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 32; @@ -330,40 +335,12 @@ public class ShortFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.SHORT_FIELD_TYPE.indexed() || - tokenized() != Defaults.SHORT_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.SHORT_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.SHORT_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.SHORT_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.SHORT_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.SHORT_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.SHORT_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.SHORT_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } if (fuzzyFactor != Defaults.FUZZY_FACTOR) { builder.field("fuzzy_factor", fuzzyFactor); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } 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 5345fed9d59..77791c5bc7b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java @@ -52,10 +52,10 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al public static final String CONTENT_TYPE = "string"; public static class Defaults extends AbstractFieldMapper.Defaults { - public static final FieldType STRING_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - STRING_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } // NOTE, when adding defaults here, make sure you add them in the builder @@ -75,7 +75,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al protected int ignoreAbove = Defaults.IGNORE_ABOVE; public Builder(String name) { - super(name, new FieldType(Defaults.STRING_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -205,6 +205,11 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al this.ignoreAbove = ignoreAbove; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public void includeInAll(Boolean includeInAll) { if (includeInAll != null) { @@ -318,31 +323,6 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.STRING_FIELD_TYPE.indexed() || - tokenized() != Defaults.STRING_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.STRING_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.STRING_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.STRING_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.STRING_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.STRING_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.STRING_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.STRING_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (nullValue != null) { builder.field("null_value", nullValue); } @@ -355,9 +335,6 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al if (searchQuotedAnalyzer != null && searchAnalyzer != searchQuotedAnalyzer) { builder.field("search_quote_analyzer", searchQuotedAnalyzer.name()); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (ignoreAbove != Defaults.IGNORE_ABOVE) { builder.field("ignore_above", ignoreAbove); } diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java index efcb4749c5e..84555e3ccd3 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -81,14 +81,14 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { public static final boolean VALIDATE_LAT = true; public static final boolean VALIDATE_LON = true; - public static final FieldType GEO_STRING_FIELD_TYPE = new FieldType(StringFieldMapper.Defaults.STRING_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(StringFieldMapper.Defaults.FIELD_TYPE); static { - GEO_STRING_FIELD_TYPE.setIndexed(true); - GEO_STRING_FIELD_TYPE.setTokenized(false); - GEO_STRING_FIELD_TYPE.setOmitNorms(true); - GEO_STRING_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - GEO_STRING_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } } @@ -543,7 +543,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { protected String nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(GeoPointFieldMapper.Defaults.GEO_STRING_FIELD_TYPE)); + super(name, new FieldType(GeoPointFieldMapper.Defaults.FIELD_TYPE)); builder = this; } @@ -575,6 +575,11 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { super(names, boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, provider, null); } + @Override + public FieldType defaultFieldType() { + return GeoPointFieldMapper.Defaults.FIELD_TYPE; + } + @Override public FieldDataType fieldDataType() { return GeoPointFieldDataType.TYPE; 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 977f5d61e3f..fb62c106f52 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java @@ -57,16 +57,16 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { public static final int QUADTREE_LEVELS = QuadPrefixTree.DEFAULT_MAX_LEVELS; public static final double DISTANCE_ERROR_PCT = 0.025d; - public static final FieldType GEO_SHAPE_FIELD_TYPE = new FieldType(); + public static final FieldType FIELD_TYPE = new FieldType(); static { - GEO_SHAPE_FIELD_TYPE.setIndexed(true); - GEO_SHAPE_FIELD_TYPE.setTokenized(false); - GEO_SHAPE_FIELD_TYPE.setStored(false); - GEO_SHAPE_FIELD_TYPE.setStoreTermVectors(false); - GEO_SHAPE_FIELD_TYPE.setOmitNorms(true); - GEO_SHAPE_FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY); - GEO_SHAPE_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setStoreTermVectors(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } } @@ -79,7 +79,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { private SpatialPrefixTree prefixTree; public Builder(String name) { - super(name, new FieldType(Defaults.GEO_SHAPE_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); } public Builder tree(String tree) { @@ -142,6 +142,11 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { this.spatialStrategy = new TermQueryPrefixTreeStrategy(names, prefixTree, distanceErrorPct); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected Field parseCreateField(ParseContext context) throws IOException { return spatialStrategy.createField(GeoJSONShapeParser.parse(context.parser())); 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 1d1d8889c4b..a733db276c9 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java @@ -66,12 +66,12 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna public static final String INDEX_NAME = AllFieldMapper.NAME; public static final boolean ENABLED = true; - public static final FieldType ALL_FIELD_TYPE = new FieldType(); + public static final FieldType FIELD_TYPE = new FieldType(); static { - ALL_FIELD_TYPE.setIndexed(true); - ALL_FIELD_TYPE.setTokenized(true); - ALL_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(true); + FIELD_TYPE.freeze(); } } @@ -83,7 +83,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna boolean autoBoost = false; public Builder() { - super(Defaults.NAME, new FieldType(Defaults.ALL_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); builder = this; indexName = Defaults.INDEX_NAME; } @@ -131,7 +131,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna private volatile boolean autoBoost; public AllFieldMapper() { - this(Defaults.NAME, new FieldType(Defaults.ALL_FIELD_TYPE), null, null, Defaults.ENABLED, false, null, null); + this(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE), null, null, Defaults.ENABLED, false, null, null); } protected AllFieldMapper(String name, FieldType fieldType, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, @@ -146,6 +146,11 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna return this.enabled; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public Query queryStringTermQuery(Term term) { if (!autoBoost) { @@ -248,8 +253,8 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no need to write it at all - if (enabled == Defaults.ENABLED && stored() == Defaults.ALL_FIELD_TYPE.stored() && - storeTermVectors() == Defaults.ALL_FIELD_TYPE.storeTermVectors() && + if (enabled == Defaults.ENABLED && stored() == Defaults.FIELD_TYPE.stored() && + storeTermVectors() == Defaults.FIELD_TYPE.storeTermVectors() && indexAnalyzer == null && searchAnalyzer == null) { return builder; } @@ -260,19 +265,19 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna if (autoBoost != false) { builder.field("auto_boost", autoBoost); } - if (stored() != Defaults.ALL_FIELD_TYPE.stored()) { + if (stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", stored()); } - if (storeTermVectors() != Defaults.ALL_FIELD_TYPE.storeTermVectors()) { + if (storeTermVectors() != Defaults.FIELD_TYPE.storeTermVectors()) { builder.field("store_term_vector", storeTermVectors()); } - if (storeTermVectorOffsets() != Defaults.ALL_FIELD_TYPE.storeTermVectorOffsets()) { + if (storeTermVectorOffsets() != Defaults.FIELD_TYPE.storeTermVectorOffsets()) { builder.field("store_term_vector_offsets", storeTermVectorOffsets()); } - if (storeTermVectorPositions() != Defaults.ALL_FIELD_TYPE.storeTermVectorPositions()) { + if (storeTermVectorPositions() != Defaults.FIELD_TYPE.storeTermVectorPositions()) { builder.field("store_term_vector_positions", storeTermVectorPositions()); } - if (storeTermVectorPayloads() != Defaults.ALL_FIELD_TYPE.storeTermVectorPayloads()) { + if (storeTermVectorPayloads() != Defaults.FIELD_TYPE.storeTermVectorPayloads()) { builder.field("store_term_vector_payloads", storeTermVectorPayloads()); } if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_")) { 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 86b77ad57bd..be61195ec1a 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java @@ -61,11 +61,11 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern public static final String NAME = "_boost"; public static final Float NULL_VALUE = null; - public static final FieldType BOOST_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - BOOST_FIELD_TYPE.setIndexed(false); - BOOST_FIELD_TYPE.setStored(false); + FIELD_TYPE.setIndexed(false); + FIELD_TYPE.setStored(false); } } @@ -74,7 +74,7 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern protected Float nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.BOOST_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -114,7 +114,7 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern } protected BoostFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.PRECISION_STEP, Defaults.BOOST, new FieldType(Defaults.BOOST_FIELD_TYPE), + this(name, indexName, Defaults.PRECISION_STEP, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Defaults.NULL_VALUE, null); } @@ -126,6 +126,11 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern this.nullValue = nullValue; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 32; 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 8d064005649..075d5380adc 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java @@ -59,14 +59,14 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern public static final String NAME = IdFieldMapper.NAME; public static final String INDEX_NAME = IdFieldMapper.NAME; - public static final FieldType ID_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - ID_FIELD_TYPE.setIndexed(false); - ID_FIELD_TYPE.setStored(false); - ID_FIELD_TYPE.setOmitNorms(true); - ID_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - ID_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(false); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } public static final String PATH = null; @@ -77,7 +77,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern private String path = Defaults.PATH; public Builder() { - super(Defaults.NAME, new FieldType(Defaults.ID_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); indexName = Defaults.INDEX_NAME; } @@ -111,7 +111,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern private final String path; public IdFieldMapper() { - this(Defaults.NAME, Defaults.INDEX_NAME, new FieldType(Defaults.ID_FIELD_TYPE)); + this(Defaults.NAME, Defaults.INDEX_NAME, new FieldType(Defaults.FIELD_TYPE)); } public IdFieldMapper(FieldType fieldType) { @@ -133,6 +133,11 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern return this.path; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public String value(Object value) { return String.valueOf(value); @@ -306,15 +311,15 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (fieldType.stored() == Defaults.ID_FIELD_TYPE.stored() && - fieldType.indexed() == Defaults.ID_FIELD_TYPE.indexed() && path == Defaults.PATH) { + if (fieldType.stored() == Defaults.FIELD_TYPE.stored() && + fieldType.indexed() == Defaults.FIELD_TYPE.indexed() && path == Defaults.PATH) { return builder; } builder.startObject(CONTENT_TYPE); - if (fieldType.stored() != Defaults.ID_FIELD_TYPE.stored()) { + if (fieldType.stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", fieldType.stored()); } - if (fieldType.indexed() != Defaults.ID_FIELD_TYPE.indexed()) { + if (fieldType.indexed() != Defaults.FIELD_TYPE.indexed()) { builder.field("index", fieldType.indexed()); } if (path != Defaults.PATH) { 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 644112566ec..03102d7023f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -50,15 +50,15 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int public static final String NAME = IndexFieldMapper.NAME; public static final String INDEX_NAME = IndexFieldMapper.NAME; - public static final FieldType INDEX_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - INDEX_FIELD_TYPE.setIndexed(true); - INDEX_FIELD_TYPE.setTokenized(false); - INDEX_FIELD_TYPE.setStored(false); - INDEX_FIELD_TYPE.setOmitNorms(true); - INDEX_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - INDEX_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } public static final boolean ENABLED = false; @@ -69,7 +69,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int private boolean enabled = Defaults.ENABLED; public Builder() { - super(Defaults.NAME, new FieldType(Defaults.INDEX_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); indexName = Defaults.INDEX_NAME; } @@ -108,7 +108,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int } protected IndexFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.BOOST, new FieldType(Defaults.INDEX_FIELD_TYPE), Defaults.ENABLED, null); + this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Defaults.ENABLED, null); } public IndexFieldMapper(String name, String indexName, float boost, FieldType fieldType, boolean enabled, @@ -122,6 +122,11 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int return this.enabled; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + public String value(Document document) { Field field = (Field) document.getField(names.indexName()); return field == null ? null : value(field); @@ -181,11 +186,11 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all defaults, no need to write it at all - if (stored() == Defaults.INDEX_FIELD_TYPE.stored() && enabled == Defaults.ENABLED) { + if (stored() == Defaults.FIELD_TYPE.stored() && enabled == Defaults.ENABLED) { return builder; } builder.startObject(CONTENT_TYPE); - if (stored() != Defaults.INDEX_FIELD_TYPE.stored()) { + if (stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", stored()); } if (enabled != Defaults.ENABLED) { 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 76fd64eb3e4..044938c6f64 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -52,15 +52,15 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter public static class Defaults extends AbstractFieldMapper.Defaults { public static final String NAME = ParentFieldMapper.NAME; - public static final FieldType PARENT_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - PARENT_FIELD_TYPE.setIndexed(true); - PARENT_FIELD_TYPE.setTokenized(false); - PARENT_FIELD_TYPE.setStored(true); - PARENT_FIELD_TYPE.setOmitNorms(true); - PARENT_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - PARENT_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(true); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } } @@ -116,7 +116,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter private final String type; protected ParentFieldMapper(String name, String indexName, String type, PostingsFormatProvider postingsFormat) { - super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.PARENT_FIELD_TYPE), + super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null); this.type = type; } @@ -125,6 +125,11 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter return type; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public void preParse(ParseContext context) throws IOException { } 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 d09e9785391..ddfe189dec1 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java @@ -49,15 +49,15 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I public static class Defaults extends AbstractFieldMapper.Defaults { public static final String NAME = "_routing"; - public static final FieldType ROUTING_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - ROUTING_FIELD_TYPE.setIndexed(true); - ROUTING_FIELD_TYPE.setTokenized(false); - ROUTING_FIELD_TYPE.setStored(true); - ROUTING_FIELD_TYPE.setOmitNorms(true); - ROUTING_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - ROUTING_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(true); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } public static final boolean REQUIRED = false; @@ -71,7 +71,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I private String path = Defaults.PATH; public Builder() { - super(Defaults.NAME, new FieldType(Defaults.ROUTING_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); } public Builder required(boolean required) { @@ -114,7 +114,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I private final String path; public RoutingFieldMapper() { - this(new FieldType(Defaults.ROUTING_FIELD_TYPE), Defaults.REQUIRED, Defaults.PATH, null); + this(new FieldType(Defaults.FIELD_TYPE), Defaults.REQUIRED, Defaults.PATH, null); } protected RoutingFieldMapper(FieldType fieldType, boolean required, String path, PostingsFormatProvider provider) { @@ -124,6 +124,11 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I this.path = path; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + public void markAsRequired() { this.required = true; } @@ -221,15 +226,15 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (indexed() == Defaults.ROUTING_FIELD_TYPE.indexed() && - stored() == Defaults.ROUTING_FIELD_TYPE.stored() && required == Defaults.REQUIRED && path == Defaults.PATH) { + if (indexed() == Defaults.FIELD_TYPE.indexed() && + stored() == Defaults.FIELD_TYPE.stored() && required == Defaults.REQUIRED && path == Defaults.PATH) { return builder; } builder.startObject(CONTENT_TYPE); - if (indexed() != Defaults.ROUTING_FIELD_TYPE.indexed()) { + if (indexed() != Defaults.FIELD_TYPE.indexed()) { builder.field("index", indexed()); } - if (stored() != Defaults.ROUTING_FIELD_TYPE.stored()) { + if (stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", stored()); } if (required != Defaults.REQUIRED) { diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java index 87e48280c34..d92cd4de2ce 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java @@ -43,7 +43,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper { public static final String NAME = CONTENT_TYPE; public static final boolean ENABLED = false; - public static final FieldType SIZE_FIELD_TYPE = new FieldType(IntegerFieldMapper.Defaults.INTEGER_FIELD_TYPE); + public static final FieldType SIZE_FIELD_TYPE = new FieldType(IntegerFieldMapper.Defaults.FIELD_TYPE); static { SIZE_FIELD_TYPE.freeze(); 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 1beed0af14b..020966c4198 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java @@ -67,14 +67,14 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In public static final long COMPRESS_THRESHOLD = -1; public static final String FORMAT = null; // default format is to use the one provided - public static final FieldType SOURCE_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - SOURCE_FIELD_TYPE.setIndexed(false); - SOURCE_FIELD_TYPE.setStored(true); - SOURCE_FIELD_TYPE.setOmitNorms(true); - SOURCE_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - SOURCE_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(false); + FIELD_TYPE.setStored(true); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } public static final String[] INCLUDES = Strings.EMPTY_ARRAY; @@ -197,7 +197,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In protected SourceFieldMapper(String name, boolean enabled, String format, Boolean compress, long compressThreshold, String[] includes, String[] excludes) { - super(new Names(name, name, name, name), Defaults.BOOST, new FieldType(Defaults.SOURCE_FIELD_TYPE), + super(new Names(name, name, name, name), Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, null, null); // Only stored. this.enabled = enabled; this.compress = compress; @@ -212,6 +212,11 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In return this.enabled; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override public void preParse(ParseContext context) throws IOException { super.parse(context); diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java index 7bda668d0e1..cefec88a58b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java @@ -49,7 +49,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R public static class Defaults extends LongFieldMapper.Defaults { public static final String NAME = TTLFieldMapper.CONTENT_TYPE; - public static final FieldType TTL_FIELD_TYPE = new FieldType(LongFieldMapper.Defaults.LONG_FIELD_TYPE); + public static final FieldType TTL_FIELD_TYPE = new FieldType(LongFieldMapper.Defaults.FIELD_TYPE); static { TTL_FIELD_TYPE.setStored(true); 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 ce5aef40775..49d8763864f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java @@ -52,13 +52,13 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap public static class Defaults extends DateFieldMapper.Defaults { public static final String NAME = "_timestamp"; - public static final FieldType TIMESTAMP_FIELD_TYPE = new FieldType(DateFieldMapper.Defaults.DATE_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(DateFieldMapper.Defaults.FIELD_TYPE); static { - TIMESTAMP_FIELD_TYPE.setStored(false); - TIMESTAMP_FIELD_TYPE.setIndexed(true); - TIMESTAMP_FIELD_TYPE.setTokenized(false); - TIMESTAMP_FIELD_TYPE.freeze(); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.freeze(); } public static final boolean ENABLED = false; @@ -73,7 +73,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap private FormatDateTimeFormatter dateTimeFormatter = Defaults.DATE_TIME_FORMATTER; public Builder() { - super(Defaults.NAME, new FieldType(Defaults.TIMESTAMP_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); } public Builder enabled(boolean enabled) { @@ -128,7 +128,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap private final String path; public TimestampFieldMapper() { - this(new FieldType(Defaults.TIMESTAMP_FIELD_TYPE), Defaults.ENABLED, Defaults.PATH, Defaults.DATE_TIME_FORMATTER, + this(new FieldType(Defaults.FIELD_TYPE), Defaults.ENABLED, Defaults.PATH, Defaults.DATE_TIME_FORMATTER, Defaults.PARSE_UPPER_INCLUSIVE, Defaults.IGNORE_MALFORMED, null); } @@ -143,6 +143,11 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap this.path = path; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + public boolean enabled() { return this.enabled; } @@ -218,16 +223,16 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (indexed() == Defaults.TIMESTAMP_FIELD_TYPE.indexed() && - stored() == Defaults.TIMESTAMP_FIELD_TYPE.stored() && enabled == Defaults.ENABLED && path == Defaults.PATH + if (indexed() == Defaults.FIELD_TYPE.indexed() && + stored() == Defaults.FIELD_TYPE.stored() && enabled == Defaults.ENABLED && path == Defaults.PATH && dateTimeFormatter.format().equals(Defaults.DATE_TIME_FORMATTER.format())) { return builder; } builder.startObject(CONTENT_TYPE); - if (indexed() != Defaults.TIMESTAMP_FIELD_TYPE.indexed()) { + if (indexed() != Defaults.FIELD_TYPE.indexed()) { builder.field("index", indexed()); } - if (stored() != Defaults.TIMESTAMP_FIELD_TYPE.stored()) { + if (stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", stored()); } if (enabled != Defaults.ENABLED) { 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 cfc9fa65173..3d463ad6e50 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper.internal; -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; @@ -58,22 +57,22 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte public static final String NAME = TypeFieldMapper.NAME; public static final String INDEX_NAME = TypeFieldMapper.NAME; - public static final FieldType TYPE_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - TYPE_FIELD_TYPE.setIndexed(true); - TYPE_FIELD_TYPE.setTokenized(false); - TYPE_FIELD_TYPE.setStored(false); - TYPE_FIELD_TYPE.setOmitNorms(true); - TYPE_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); - TYPE_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY); + FIELD_TYPE.freeze(); } } public static class Builder extends AbstractFieldMapper.Builder { public Builder() { - super(Defaults.NAME, new FieldType(Defaults.TYPE_FIELD_TYPE)); + super(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE)); indexName = Defaults.INDEX_NAME; } @@ -98,7 +97,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte } protected TypeFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.BOOST, new FieldType(Defaults.TYPE_FIELD_TYPE), null); + this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), null); } public TypeFieldMapper(String name, String indexName, float boost, FieldType fieldType, PostingsFormatProvider provider) { @@ -106,9 +105,9 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte Lucene.KEYWORD_ANALYZER, provider, null); } - public String value(Document document) { - Field field = (Field) document.getField(names.indexName()); - return field == null ? null : value(field); + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; } @Override @@ -182,14 +181,14 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (stored() == Defaults.TYPE_FIELD_TYPE.stored() && indexed() == Defaults.TYPE_FIELD_TYPE.indexed()) { + if (stored() == Defaults.FIELD_TYPE.stored() && indexed() == Defaults.FIELD_TYPE.indexed()) { return builder; } builder.startObject(CONTENT_TYPE); - if (stored() != Defaults.TYPE_FIELD_TYPE.stored()) { + if (stored() != Defaults.FIELD_TYPE.stored()) { builder.field("store", stored()); } - if (indexed() != Defaults.TYPE_FIELD_TYPE.indexed()) { + if (indexed() != Defaults.FIELD_TYPE.indexed()) { builder.field("index", indexed()); } builder.endObject(); 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 58b5a4dd9f1..0ccc52e4631 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -48,15 +48,15 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal public static class Defaults extends AbstractFieldMapper.Defaults { public static final String NAME = UidFieldMapper.NAME; - public static final FieldType UID_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE); static { - UID_FIELD_TYPE.setIndexed(true); - UID_FIELD_TYPE.setTokenized(false); - UID_FIELD_TYPE.setStored(true); - UID_FIELD_TYPE.setOmitNorms(true); - UID_FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); // we store payload (otherwise, we really need just docs) - UID_FIELD_TYPE.freeze(); + FIELD_TYPE.setIndexed(true); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setStored(true); + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); // we store payload (otherwise, we really need just docs) + FIELD_TYPE.freeze(); } } @@ -108,10 +108,15 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal } protected UidFieldMapper(String name, String indexName, PostingsFormatProvider postingsFormat) { - super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.UID_FIELD_TYPE), + super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null); } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected String defaultPostingFormat() { return "bloom_default"; @@ -204,12 +209,32 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - // for now, don't output it at all + // if defaults, don't output + if ((postingsFormat == null || postingsFormat.name().equals(defaultPostingFormat()))) { + return builder; + } + + builder.startObject(CONTENT_TYPE); + + if (postingsFormat != null) { + if (!postingsFormat.name().equals(defaultPostingFormat())) { + builder.field("postings_format", postingsFormat.name()); + } + } + + builder.endObject(); return builder; } @Override public void merge(Mapper mergeWith, MergeContext mergeContext) throws MergeMappingException { + AbstractFieldMapper fieldMergeWith = (AbstractFieldMapper) mergeWith; // do nothing here, no merging, but also no exception + if (!mergeContext.mergeFlags().simulate()) { + // apply changeable values + if (fieldMergeWith.postingsFormatProvider() != null) { + this.postingsFormat = fieldMergeWith.postingsFormatProvider(); + } + } } } 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 0ae90e54d98..9937111311c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java @@ -89,10 +89,10 @@ public class IpFieldMapper extends NumberFieldMapper { public static class Defaults extends NumberFieldMapper.Defaults { public static final String NULL_VALUE = null; - public static final FieldType IP_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE); + public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); static { - IP_FIELD_TYPE.freeze(); + FIELD_TYPE.freeze(); } } @@ -101,7 +101,7 @@ public class IpFieldMapper extends NumberFieldMapper { protected String nullValue = Defaults.NULL_VALUE; public Builder(String name) { - super(name, new FieldType(Defaults.IP_FIELD_TYPE)); + super(name, new FieldType(Defaults.FIELD_TYPE)); builder = this; } @@ -148,6 +148,11 @@ public class IpFieldMapper extends NumberFieldMapper { this.nullValue = nullValue; } + @Override + public FieldType defaultFieldType() { + return Defaults.FIELD_TYPE; + } + @Override protected int maxPrecisionStep() { return 64; @@ -305,37 +310,9 @@ public class IpFieldMapper extends NumberFieldMapper { @Override protected void doXContentBody(XContentBuilder builder) throws IOException { super.doXContentBody(builder); - if (indexed() != Defaults.IP_FIELD_TYPE.indexed() || - tokenized() != Defaults.IP_FIELD_TYPE.tokenized()) { - builder.field("index", indexTokenizeOptionToString(indexed(), tokenized())); - } - if (stored() != Defaults.IP_FIELD_TYPE.stored()) { - builder.field("store", stored()); - } - if (storeTermVectors() != Defaults.IP_FIELD_TYPE.storeTermVectors()) { - builder.field("store_term_vector", storeTermVectors()); - } - if (storeTermVectorOffsets() != Defaults.IP_FIELD_TYPE.storeTermVectorOffsets()) { - builder.field("store_term_vector_offsets", storeTermVectorOffsets()); - } - if (storeTermVectorPositions() != Defaults.IP_FIELD_TYPE.storeTermVectorPositions()) { - builder.field("store_term_vector_positions", storeTermVectorPositions()); - } - if (storeTermVectorPayloads() != Defaults.IP_FIELD_TYPE.storeTermVectorPayloads()) { - builder.field("store_term_vector_payloads", storeTermVectorPayloads()); - } - if (omitNorms() != Defaults.IP_FIELD_TYPE.omitNorms()) { - builder.field("omit_norms", omitNorms()); - } - if (indexOptions() != Defaults.IP_FIELD_TYPE.indexOptions()) { - builder.field("index_options", indexOptionToString(indexOptions())); - } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); } - if (similarity() != null) { - builder.field("similarity", similarity().name()); - } if (nullValue != null) { builder.field("null_value", nullValue); } diff --git a/src/test/java/org/elasticsearch/test/unit/common/lucene/uid/UidFieldTests.java b/src/test/java/org/elasticsearch/test/unit/common/lucene/uid/UidFieldTests.java index bf4042ab3e1..5a3e9685803 100644 --- a/src/test/java/org/elasticsearch/test/unit/common/lucene/uid/UidFieldTests.java +++ b/src/test/java/org/elasticsearch/test/unit/common/lucene/uid/UidFieldTests.java @@ -47,7 +47,7 @@ public class UidFieldTests { MatcherAssert.assertThat(UidField.loadVersion(atomicReader.getContext(), new Term("_uid", "1")), equalTo(-1l)); Document doc = new Document(); - doc.add(new Field("_uid", "1", UidFieldMapper.Defaults.UID_FIELD_TYPE)); + doc.add(new Field("_uid", "1", UidFieldMapper.Defaults.FIELD_TYPE)); writer.addDocument(doc); directoryReader = DirectoryReader.openIfChanged(directoryReader); atomicReader = SlowCompositeReaderWrapper.wrap(directoryReader); diff --git a/src/test/java/org/elasticsearch/test/unit/index/codec/CodecTests.java b/src/test/java/org/elasticsearch/test/unit/index/codec/CodecTests.java index 609c2bb032b..a9def7a0444 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/codec/CodecTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/codec/CodecTests.java @@ -113,11 +113,11 @@ public class CodecTests { .build(); CodecService codecService = createCodecService(indexSettings); DocumentMapper documentMapper = codecService.mapperService().documentMapperParser().parse(mapping); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider().get(), instanceOf(Lucene40PostingsFormat.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider().get(), instanceOf(Lucene40PostingsFormat.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider(), instanceOf(DefaultPostingsFormatProvider.class)); - DefaultPostingsFormatProvider provider = (DefaultPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingFormatProvider(); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider(), instanceOf(DefaultPostingsFormatProvider.class)); + DefaultPostingsFormatProvider provider = (DefaultPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingsFormatProvider(); assertThat(provider.minBlockSize(), equalTo(16)); assertThat(provider.maxBlockSize(), equalTo(64)); } @@ -138,11 +138,11 @@ public class CodecTests { .build(); CodecService codecService = createCodecService(indexSettings); DocumentMapper documentMapper = codecService.mapperService().documentMapperParser().parse(mapping); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider().get(), instanceOf(MemoryPostingsFormat.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider().get(), instanceOf(MemoryPostingsFormat.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider(), instanceOf(MemoryPostingsFormatProvider.class)); - MemoryPostingsFormatProvider provider = (MemoryPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingFormatProvider(); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider(), instanceOf(MemoryPostingsFormatProvider.class)); + MemoryPostingsFormatProvider provider = (MemoryPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingsFormatProvider(); assertThat(provider.packFst(), equalTo(true)); assertThat(provider.acceptableOverheadRatio(), equalTo(0.3f)); } @@ -163,11 +163,11 @@ public class CodecTests { .build(); CodecService codecService = createCodecService(indexSettings); DocumentMapper documentMapper = codecService.mapperService().documentMapperParser().parse(mapping); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider().get(), instanceOf(DirectPostingsFormat.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider().get(), instanceOf(DirectPostingsFormat.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider(), instanceOf(DirectPostingsFormatProvider.class)); - DirectPostingsFormatProvider provider = (DirectPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingFormatProvider(); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider(), instanceOf(DirectPostingsFormatProvider.class)); + DirectPostingsFormatProvider provider = (DirectPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingsFormatProvider(); assertThat(provider.minSkipCount(), equalTo(16)); assertThat(provider.lowFreqCutoff(), equalTo(64)); } @@ -189,11 +189,11 @@ public class CodecTests { .build(); CodecService codecService = createCodecService(indexSettings); DocumentMapper documentMapper = codecService.mapperService().documentMapperParser().parse(mapping); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider().get(), instanceOf(Pulsing40PostingsFormat.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider().get(), instanceOf(Pulsing40PostingsFormat.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider(), instanceOf(PulsingPostingsFormatProvider.class)); - PulsingPostingsFormatProvider provider = (PulsingPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingFormatProvider(); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider(), instanceOf(PulsingPostingsFormatProvider.class)); + PulsingPostingsFormatProvider provider = (PulsingPostingsFormatProvider) documentMapper.mappers().name("field2").mapper().postingsFormatProvider(); assertThat(provider.freqCutOff(), equalTo(2)); assertThat(provider.minBlockSize(), equalTo(32)); assertThat(provider.maxBlockSize(), equalTo(64)); @@ -220,14 +220,14 @@ public class CodecTests { .build(); CodecService codecService = createCodecService(indexSettings); DocumentMapper documentMapper = codecService.mapperService().documentMapperParser().parse(mapping); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field1").mapper().postingFormatProvider().get(), instanceOf(BloomFilteringPostingsFormat.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field1").mapper().postingsFormatProvider().get(), instanceOf(BloomFilteringPostingsFormat.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); - assertThat(documentMapper.mappers().name("field2").mapper().postingFormatProvider().get(), instanceOf(BloomFilteringPostingsFormat.class)); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider(), instanceOf(PreBuiltPostingsFormatProvider.class)); + assertThat(documentMapper.mappers().name("field2").mapper().postingsFormatProvider().get(), instanceOf(BloomFilteringPostingsFormat.class)); - assertThat(documentMapper.mappers().name("field3").mapper().postingFormatProvider(), instanceOf(BloomFilterPostingsFormatProvider.class)); - BloomFilterPostingsFormatProvider provider = (BloomFilterPostingsFormatProvider) documentMapper.mappers().name("field3").mapper().postingFormatProvider(); + assertThat(documentMapper.mappers().name("field3").mapper().postingsFormatProvider(), instanceOf(BloomFilterPostingsFormatProvider.class)); + BloomFilterPostingsFormatProvider provider = (BloomFilterPostingsFormatProvider) documentMapper.mappers().name("field3").mapper().postingsFormatProvider(); assertThat(provider.desiredMaxSaturation(), equalTo(0.2f)); assertThat(provider.saturationLimit(), equalTo(0.8f)); assertThat(provider.delegate(), instanceOf(DirectPostingsFormatProvider.class)); diff --git a/src/test/java/org/elasticsearch/test/unit/index/engine/AbstractSimpleEngineTests.java b/src/test/java/org/elasticsearch/test/unit/index/engine/AbstractSimpleEngineTests.java index 5c3c6d95d21..0eb64605f15 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/engine/AbstractSimpleEngineTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/engine/AbstractSimpleEngineTests.java @@ -231,7 +231,7 @@ public abstract class AbstractSimpleEngineTests { // create a document Document document = testDocumentWithTextField("1"); - document.add(new Field(SourceFieldMapper.NAME, B_1.toBytes(), SourceFieldMapper.Defaults.SOURCE_FIELD_TYPE)); + document.add(new Field(SourceFieldMapper.NAME, B_1.toBytes(), SourceFieldMapper.Defaults.FIELD_TYPE)); ParsedDocument doc = new ParsedDocument("1", "1", "test", null, -1, -1, document, Lucene.STANDARD_ANALYZER, B_1, false); engine.create(new Engine.Create(null, newUid("1"), doc)); @@ -268,7 +268,7 @@ public abstract class AbstractSimpleEngineTests { // now do an update document = testDocument("1"); document.add(new TextField("value", "test1", Field.Store.YES)); - document.add(new Field(SourceFieldMapper.NAME, B_2.toBytes(), SourceFieldMapper.Defaults.SOURCE_FIELD_TYPE)); + document.add(new Field(SourceFieldMapper.NAME, B_2.toBytes(), SourceFieldMapper.Defaults.FIELD_TYPE)); doc = new ParsedDocument("1", "1", "test", null, -1, -1, document, Lucene.STANDARD_ANALYZER, B_2, false); engine.index(new Engine.Index(null, newUid("1"), doc)); @@ -319,7 +319,7 @@ public abstract class AbstractSimpleEngineTests { // add it back document = testDocumentWithTextField("1"); - document.add(new Field(SourceFieldMapper.NAME, B_1.toBytes(), SourceFieldMapper.Defaults.SOURCE_FIELD_TYPE)); + document.add(new Field(SourceFieldMapper.NAME, B_1.toBytes(), SourceFieldMapper.Defaults.FIELD_TYPE)); doc = new ParsedDocument("1", "1", "test", null, -1, -1, document, Lucene.STANDARD_ANALYZER, B_1, false); engine.create(new Engine.Create(null, newUid("1"), doc)); diff --git a/src/test/java/org/elasticsearch/test/unit/index/mapper/timestamp/TimestampMappingTests.java b/src/test/java/org/elasticsearch/test/unit/index/mapper/timestamp/TimestampMappingTests.java index 810ae221346..539ea2da3d0 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/mapper/timestamp/TimestampMappingTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/mapper/timestamp/TimestampMappingTests.java @@ -73,8 +73,8 @@ public class TimestampMappingTests { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(); DocumentMapper docMapper = MapperTests.newParser().parse(mapping); assertThat(docMapper.timestampFieldMapper().enabled(), equalTo(TimestampFieldMapper.Defaults.ENABLED)); - assertThat(docMapper.timestampFieldMapper().stored(), equalTo(TimestampFieldMapper.Defaults.TIMESTAMP_FIELD_TYPE.stored())); - assertThat(docMapper.timestampFieldMapper().indexed(), equalTo(TimestampFieldMapper.Defaults.TIMESTAMP_FIELD_TYPE.indexed())); + assertThat(docMapper.timestampFieldMapper().stored(), equalTo(TimestampFieldMapper.Defaults.FIELD_TYPE.stored())); + assertThat(docMapper.timestampFieldMapper().indexed(), equalTo(TimestampFieldMapper.Defaults.FIELD_TYPE.indexed())); assertThat(docMapper.timestampFieldMapper().path(), equalTo(null)); assertThat(docMapper.timestampFieldMapper().dateTimeFormatter().format(), equalTo(TimestampFieldMapper.DEFAULT_DATE_TIME_FORMAT)); }