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 5ee779c7824..5223f777b3e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -33,10 +33,13 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.RegexpFilter; import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XTermsFilter; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingFormats; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.similarity.SimilarityProvider; @@ -140,6 +143,10 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { public T similarity(SimilarityProvider similarity) { return super.similarity(similarity); } + + public T fieldDataSettings(String settings) { + return super.fieldDataSettings(settings); + } } public abstract static class Builder extends Mapper.Builder { @@ -154,6 +161,8 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected boolean indexOptionsSet = false; protected PostingsFormatProvider provider; protected SimilarityProvider similarity; + @Nullable + protected Settings fieldDataSettings; protected Builder(String name, FieldType fieldType) { super(name); @@ -245,6 +254,11 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { return builder; } + protected T fieldDataSettings(String settings) { + this.fieldDataSettings = ImmutableSettings.builder().loadFromDelimitedString(settings, ';').build(); + return builder; + } + protected Names buildNames(BuilderContext context) { return new Names(name, buildIndexName(context), indexName == null ? name : indexName, buildFullName(context), context.path().sourcePath()); } @@ -267,8 +281,12 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected PostingsFormatProvider postingsFormat; protected final SimilarityProvider similarity; + protected Settings customFieldDataSettings; + protected FieldDataType fieldDataType; + protected AbstractFieldMapper(Names names, float boost, FieldType fieldType, NamedAnalyzer indexAnalyzer, - NamedAnalyzer searchAnalyzer, PostingsFormatProvider postingsFormat, SimilarityProvider similarity) { + NamedAnalyzer searchAnalyzer, PostingsFormatProvider postingsFormat, SimilarityProvider similarity, + @Nullable Settings fieldDataSettings) { this.names = names; this.boost = boost; this.fieldType = fieldType; @@ -293,6 +311,16 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { } this.postingsFormat = postingsFormat; this.similarity = similarity; + + this.customFieldDataSettings = fieldDataSettings; + if (fieldDataSettings == null) { + this.fieldDataType = defaultFieldDataType(); + } else { + // create a new field data type, with the default settings as well as the "new ones" + this.fieldDataType = new FieldDataType(defaultFieldDataType().getType(), + ImmutableSettings.builder().put(defaultFieldDataType().getSettings()).put(fieldDataSettings) + ); + } } @Nullable @@ -312,6 +340,13 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { public abstract FieldType defaultFieldType(); + public abstract FieldDataType defaultFieldDataType(); + + @Override + public final FieldDataType fieldDataType() { + return fieldDataType; + } + @Override public FieldType fieldType() { return fieldType; @@ -547,6 +582,12 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { if (fieldMergeWith.postingsFormat != null) { this.postingsFormat = fieldMergeWith.postingsFormat; } + if (fieldMergeWith.customFieldDataSettings != null) { + this.customFieldDataSettings = fieldMergeWith.customFieldDataSettings; + this.fieldDataType = new FieldDataType(defaultFieldDataType().getType(), + ImmutableSettings.builder().put(defaultFieldDataType().getSettings()).put(this.customFieldDataSettings) + ); + } } } @@ -620,6 +661,10 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { if (similarity() != null) { builder.field("similarity", similarity().name()); } + + if (customFieldDataSettings != null) { + builder.field("fielddata", customFieldDataSettings.toDelimitedString(';')); + } } protected static String indexOptionToString(IndexOptions indexOption) { 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 b43542b801c..8bc6243ccd8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Base64; import org.elasticsearch.common.Strings; @@ -35,6 +34,7 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.mapper.*; import java.io.IOException; @@ -123,7 +123,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper { private long compressThreshold; protected BinaryFieldMapper(Names names, FieldType fieldType, Boolean compress, long compressThreshold, PostingsFormatProvider provider) { - super(names, 1.0f, fieldType, null, null, provider, null); + super(names, 1.0f, fieldType, null, null, provider, null, null); this.compress = compress; this.compressThreshold = compressThreshold; } @@ -134,8 +134,8 @@ public class BinaryFieldMapper extends AbstractFieldMapper { } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - throw new ElasticSearchIllegalArgumentException("field data on binary field is not supported"); + public FieldDataType defaultFieldDataType() { + return null; } @Override 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 3d8a0e9515f..830a7c777c5 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -24,9 +24,11 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Booleans; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.TermFilter; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; @@ -128,7 +130,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper { @Override public BooleanFieldMapper build(BuilderContext context) { - return new BooleanFieldMapper(buildNames(context), boost, fieldType, nullValue, provider, similarity); + return new BooleanFieldMapper(buildNames(context), boost, fieldType, nullValue, provider, similarity, fieldDataSettings); } } @@ -150,8 +152,8 @@ public class BooleanFieldMapper extends AbstractFieldMapper { private Boolean nullValue; - protected BooleanFieldMapper(Names names, float boost, FieldType fieldType, Boolean nullValue, PostingsFormatProvider provider, SimilarityProvider similarity) { - super(names, boost, fieldType, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, provider, similarity); + protected BooleanFieldMapper(Names names, float boost, FieldType fieldType, Boolean nullValue, PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { + super(names, boost, fieldType, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, provider, similarity, fieldDataSettings); this.nullValue = nullValue; } @@ -161,7 +163,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { // TODO have a special boolean type? return new FieldDataType("string"); } 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 0ec5cd3f959..4239a12523f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java @@ -33,6 +33,7 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -89,7 +90,7 @@ public class ByteFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context), - provider, similarity); + provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -116,10 +117,10 @@ public class ByteFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected ByteFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, - Byte nullValue, Explicit ignoreMalformed, PostingsFormatProvider provider, SimilarityProvider similarity) { + Byte nullValue, Explicit ignoreMalformed, PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_byte/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), - new NamedAnalyzer("_byte/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_byte/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -130,7 +131,7 @@ public class ByteFieldMapper extends NumberFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("byte"); } 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 0588fcd161c..db22e55de44 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -116,7 +117,7 @@ public class DateFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter, precisionStep, fuzzyFactor, boost, fieldType, nullValue, - timeUnit, parseUpperInclusive, ignoreMalformed(context), provider, similarity); + timeUnit, parseUpperInclusive, ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -155,12 +156,12 @@ public class DateFieldMapper extends NumberFieldMapper { protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, String nullValue, TimeUnit timeUnit, boolean parseUpperInclusive, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_date/" + precisionStep, new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())), new NamedAnalyzer("_date/max", new NumericDateAnalyzer(Integer.MAX_VALUE, dateTimeFormatter.parser())), - provider, similarity); + provider, similarity, fieldDataSettings); this.dateTimeFormatter = dateTimeFormatter; this.nullValue = nullValue; this.timeUnit = timeUnit; @@ -174,7 +175,7 @@ public class DateFieldMapper extends NumberFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("long"); } 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 97847bc6742..7eedf0e09d8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java @@ -33,6 +33,7 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -89,7 +90,7 @@ public class DoubleFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, - ignoreMalformed(context), provider, similarity); + ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -119,10 +120,10 @@ public class DoubleFieldMapper extends NumberFieldMapper { protected DoubleFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, Double nullValue, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_double/" + precisionStep, new NumericDoubleAnalyzer(precisionStep)), - new NamedAnalyzer("_double/max", new NumericDoubleAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_double/max", new NumericDoubleAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -133,7 +134,7 @@ public class DoubleFieldMapper extends NumberFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("double"); } 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 52f52f9129e..bd56399128b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -90,7 +91,7 @@ public class FloatFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, - ignoreMalformed(context), provider, similarity); + ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -117,10 +118,10 @@ public class FloatFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected FloatFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, - Float nullValue, Explicit ignoreMalformed, PostingsFormatProvider provider, SimilarityProvider similarity) { + Float nullValue, Explicit ignoreMalformed, PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)), - new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -131,7 +132,7 @@ public class FloatFieldMapper extends NumberFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("float"); } 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 aaa045c0648..51b5437b1d2 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java @@ -34,11 +34,13 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.mapper.*; @@ -89,7 +91,7 @@ public class IntegerFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, - nullValue, ignoreMalformed(context), provider, similarity); + nullValue, ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -118,10 +120,10 @@ public class IntegerFieldMapper extends NumberFieldMapper { protected IntegerFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, Integer nullValue, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_int/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), - new NamedAnalyzer("_int/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_int/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -132,8 +134,8 @@ public class IntegerFieldMapper extends NumberFieldMapper { } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - return new org.elasticsearch.index.fielddata.FieldDataType("int"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("int"); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java index b1f86650636..cfcbff4245c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -90,7 +91,7 @@ public class LongFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, - ignoreMalformed(context), provider, similarity); + ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -119,10 +120,10 @@ public class LongFieldMapper extends NumberFieldMapper { protected LongFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, Long nullValue, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_long/" + precisionStep, new NumericLongAnalyzer(precisionStep)), - new NamedAnalyzer("_long/max", new NumericLongAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_long/max", new NumericLongAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -133,7 +134,7 @@ public class LongFieldMapper extends NumberFieldMapper { } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("long"); } 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 ca0d9415660..214e96d0f56 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java @@ -28,6 +28,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; @@ -140,9 +141,10 @@ public abstract class NumberFieldMapper extends AbstractFieldM protected NumberFieldMapper(Names names, int precisionStep, @Nullable String fuzzyFactor, float boost, FieldType fieldType, Explicit ignoreMalformed, NamedAnalyzer indexAnalyzer, - NamedAnalyzer searchAnalyzer, PostingsFormatProvider provider, SimilarityProvider similarity) { + NamedAnalyzer searchAnalyzer, PostingsFormatProvider provider, SimilarityProvider similarity, + @Nullable Settings fieldDataSettings) { // LUCENE 4 UPGRADE: Since we can't do anything before the super call, we have to push the boost check down to subclasses - super(names, boost, fieldType, indexAnalyzer, searchAnalyzer, provider, similarity); + super(names, boost, fieldType, indexAnalyzer, searchAnalyzer, provider, similarity, fieldDataSettings); if (precisionStep <= 0 || precisionStep >= maxPrecisionStep()) { this.precisionStep = Integer.MAX_VALUE; } else { 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 65afdf63e15..0014d12633d 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java @@ -34,11 +34,13 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.mapper.*; @@ -89,7 +91,7 @@ public class ShortFieldMapper extends NumberFieldMapper { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context), precisionStep, fuzzyFactor, boost, fieldType, nullValue, - ignoreMalformed(context), provider, similarity); + ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -118,10 +120,10 @@ public class ShortFieldMapper extends NumberFieldMapper { protected ShortFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType, Short nullValue, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, fuzzyFactor, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_short/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), - new NamedAnalyzer("_short/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_short/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; this.nullValueAsString = nullValue == null ? null : nullValue.toString(); } @@ -132,8 +134,8 @@ public class ShortFieldMapper extends NumberFieldMapper { } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - return new org.elasticsearch.index.fielddata.FieldDataType("short"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("short"); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java index 20d89f27674..933b57905dc 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java @@ -28,7 +28,9 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; @@ -136,7 +138,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al } StringFieldMapper fieldMapper = new StringFieldMapper(buildNames(context), boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, searchQuotedAnalyzer, - positionOffsetGap, ignoreAbove, provider, similarity); + positionOffsetGap, ignoreAbove, provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -189,18 +191,11 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al private int ignoreAbove; - protected StringFieldMapper(Names names, float boost, FieldType fieldType, - String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, - PostingsFormatProvider postingsFormat, SimilarityProvider similarity) { - this(names, boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, searchAnalyzer, - Defaults.POSITION_OFFSET_GAP, Defaults.IGNORE_ABOVE, postingsFormat, similarity); - } - protected StringFieldMapper(Names names, float boost, FieldType fieldType, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, NamedAnalyzer searchQuotedAnalyzer, int positionOffsetGap, int ignoreAbove, - PostingsFormatProvider postingsFormat, SimilarityProvider similarity) { - super(names, boost, fieldType, indexAnalyzer, searchAnalyzer, postingsFormat, similarity); + PostingsFormatProvider postingsFormat, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { + super(names, boost, fieldType, indexAnalyzer, searchAnalyzer, postingsFormat, similarity, fieldDataSettings); this.nullValue = nullValue; this.positionOffsetGap = positionOffsetGap; this.searchQuotedAnalyzer = searchQuotedAnalyzer != null ? searchQuotedAnalyzer : this.searchAnalyzer; @@ -213,7 +208,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } diff --git a/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java b/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java index 65d650f7d93..9ec9fac17d0 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java @@ -118,6 +118,8 @@ public class TypeParsers { builder.postingsFormat(parserContext.postingFormatService().get(postingFormatName)); } else if (propName.equals("similarity")) { builder.similarity(parserContext.similarityLookupService().similarity(propNode.toString())); + } else if (propName.equals("fielddata")) { + builder.fieldDataSettings(propNode.toString()); } } } 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 d9c553b9a27..b3a52c24164 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -22,15 +22,18 @@ package org.elasticsearch.index.mapper.geo; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.geo.GeoHashUtils; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.core.AbstractFieldMapper; import org.elasticsearch.index.mapper.core.DoubleFieldMapper; @@ -559,7 +562,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { @Override public GeoStringFieldMapper build(BuilderContext context) { GeoStringFieldMapper fieldMapper = new GeoStringFieldMapper(buildNames(context), - boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, provider); + boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, provider, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -569,8 +572,9 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { public GeoStringFieldMapper(Names names, float boost, FieldType fieldType, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, - PostingsFormatProvider provider) { - super(names, boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, provider, null); + PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { + super(names, boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer, searchAnalyzer, Defaults.POSITION_OFFSET_GAP, Defaults.IGNORE_ABOVE, + provider, null, fieldDataSettings); } @Override @@ -579,8 +583,8 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - return new org.elasticsearch.index.fielddata.FieldDataType("geo_point"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("geo_point"); } public GeoPointFieldMapper geoMapper() { 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 408742bd08a..2395cd5f17d 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoShapeFieldMapper.java @@ -139,7 +139,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { public GeoShapeFieldMapper(FieldMapper.Names names, SpatialPrefixTree prefixTree, double distanceErrorPct, FieldType fieldType, PostingsFormatProvider provider) { - super(names, 1, fieldType, null, null, provider, null); + super(names, 1, fieldType, null, null, provider, null, null); this.spatialStrategy = new TermQueryPrefixTreeStrategy(names, prefixTree, distanceErrorPct); } @@ -149,8 +149,8 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper { } @Override - public FieldDataType fieldDataType() { - throw new ElasticSearchIllegalArgumentException("field data on geo_shape field is not supported"); + public FieldDataType defaultFieldDataType() { + return null; } @Override 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 32b573c238d..5287c79d497 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java @@ -26,14 +26,16 @@ import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; -import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.all.AllField; import org.elasticsearch.common.lucene.all.AllTermQuery; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.core.AbstractFieldMapper; import org.elasticsearch.index.query.QueryParseContext; @@ -100,7 +102,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna fieldType.setIndexed(true); fieldType.setTokenized(true); - return new AllFieldMapper(name, fieldType, indexAnalyzer, searchAnalyzer, enabled, autoBoost, provider, similarity); + return new AllFieldMapper(name, fieldType, indexAnalyzer, searchAnalyzer, enabled, autoBoost, provider, similarity, fieldDataSettings); } } @@ -132,12 +134,12 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna private volatile boolean autoBoost; public AllFieldMapper() { - this(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE), null, null, Defaults.ENABLED, false, null, null); + this(Defaults.NAME, new FieldType(Defaults.FIELD_TYPE), null, null, Defaults.ENABLED, false, null, null, null); } protected AllFieldMapper(String name, FieldType fieldType, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, - boolean enabled, boolean autoBoost, PostingsFormatProvider provider, SimilarityProvider similarity) { - super(new Names(name, name, name, name), 1.0f, fieldType, indexAnalyzer, searchAnalyzer, provider, similarity); + boolean enabled, boolean autoBoost, PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { + super(new Names(name, name, name, name), 1.0f, fieldType, indexAnalyzer, searchAnalyzer, provider, similarity, fieldDataSettings); this.enabled = enabled; this.autoBoost = autoBoost; @@ -153,8 +155,8 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - throw new ElasticSearchIllegalArgumentException("using field data on _all field is not supported"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("string"); } @Override 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 54c7ebe0c36..e6c47b04aba 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java @@ -27,10 +27,10 @@ import org.apache.lucene.search.NumericRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; -import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -88,7 +88,7 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern @Override public BoostFieldMapper build(BuilderContext context) { return new BoostFieldMapper(name, buildIndexName(context), - precisionStep, boost, fieldType, nullValue, provider); + precisionStep, boost, fieldType, nullValue, provider, fieldDataSettings); } } @@ -117,14 +117,14 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern protected BoostFieldMapper(String name, String indexName) { this(name, indexName, Defaults.PRECISION_STEP, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), - Defaults.NULL_VALUE, null); + Defaults.NULL_VALUE, null, null); } protected BoostFieldMapper(String name, String indexName, int precisionStep, float boost, FieldType fieldType, - Float nullValue, PostingsFormatProvider provider) { + Float nullValue, PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(name, indexName, indexName, name), precisionStep, null, boost, fieldType, Defaults.IGNORE_MALFORMED, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)), - new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)), provider, null); + new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)), provider, null, fieldDataSettings); this.nullValue = nullValue; } @@ -134,8 +134,8 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern } @Override - public FieldDataType fieldDataType() { - throw new ElasticSearchIllegalArgumentException("not implemented"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("float"); } @Override diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java index d358abd9269..74165ad720f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.RegexpFilter; import org.elasticsearch.common.lucene.search.XBooleanFilter; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; @@ -93,7 +94,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern @Override public IdFieldMapper build(BuilderContext context) { - return new IdFieldMapper(name, indexName, boost, fieldType, path, provider); + return new IdFieldMapper(name, indexName, boost, fieldType, path, provider, fieldDataSettings); } } @@ -124,13 +125,13 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern } protected IdFieldMapper(String name, String indexName, FieldType fieldType) { - this(name, indexName, Defaults.BOOST, fieldType, Defaults.PATH, null); + this(name, indexName, Defaults.BOOST, fieldType, Defaults.PATH, null, null); } protected IdFieldMapper(String name, String indexName, float boost, FieldType fieldType, String path, - PostingsFormatProvider provider) { + PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER, - Lucene.KEYWORD_ANALYZER, provider, null); + Lucene.KEYWORD_ANALYZER, provider, null, fieldDataSettings); this.path = path; } @@ -144,7 +145,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } 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 8f63659fca4..b3a77384de9 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -23,8 +23,10 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.fielddata.FieldDataType; @@ -80,7 +82,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int @Override public IndexFieldMapper build(BuilderContext context) { - return new IndexFieldMapper(name, indexName, boost, fieldType, enabled, provider); + return new IndexFieldMapper(name, indexName, boost, fieldType, enabled, provider, fieldDataSettings); } } @@ -108,13 +110,13 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int } protected IndexFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Defaults.ENABLED, null); + this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), Defaults.ENABLED, null, null); } public IndexFieldMapper(String name, String indexName, float boost, FieldType fieldType, boolean enabled, - PostingsFormatProvider provider) { + PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER, - Lucene.KEYWORD_ANALYZER, provider, null); + Lucene.KEYWORD_ANALYZER, provider, null, fieldDataSettings); this.enabled = enabled; } @@ -128,7 +130,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } 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 721bcf54ee4..60e1a05b90b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.XTermsFilter; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.fielddata.FieldDataType; @@ -94,7 +95,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter if (type == null) { throw new MapperParsingException("Parent mapping must contain the parent type"); } - return new ParentFieldMapper(name, indexName, type, postingsFormat); + return new ParentFieldMapper(name, indexName, type, postingsFormat, null); } } @@ -119,9 +120,9 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter private final String type; private final BytesRef typeAsBytes; - protected ParentFieldMapper(String name, String indexName, String type, PostingsFormatProvider postingsFormat) { + protected ParentFieldMapper(String name, String indexName, String type, PostingsFormatProvider postingsFormat, @Nullable Settings fieldDataSettings) { super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null); + Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null, fieldDataSettings); this.type = type; this.typeAsBytes = new BytesRef(type); } @@ -136,7 +137,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } 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 e424f82174a..d87bd854f27 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java @@ -23,8 +23,10 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.fielddata.FieldDataType; @@ -87,7 +89,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I @Override public RoutingFieldMapper build(BuilderContext context) { - return new RoutingFieldMapper(fieldType, required, path, provider); + return new RoutingFieldMapper(fieldType, required, path, provider, fieldDataSettings); } } @@ -115,12 +117,12 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I private final String path; public RoutingFieldMapper() { - this(new FieldType(Defaults.FIELD_TYPE), Defaults.REQUIRED, Defaults.PATH, null); + this(new FieldType(Defaults.FIELD_TYPE), Defaults.REQUIRED, Defaults.PATH, null, null); } - protected RoutingFieldMapper(FieldType fieldType, boolean required, String path, PostingsFormatProvider provider) { + protected RoutingFieldMapper(FieldType fieldType, boolean required, String path, PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), 1.0f, fieldType, Lucene.KEYWORD_ANALYZER, - Lucene.KEYWORD_ANALYZER, provider, null); + Lucene.KEYWORD_ANALYZER, provider, null, fieldDataSettings); this.required = required; this.path = path; } @@ -131,7 +133,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } 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 ff68fe8ef0a..a19766a6dbd 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java @@ -21,7 +21,9 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.mapper.*; @@ -71,7 +73,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper { @Override public SizeFieldMapper build(BuilderContext context) { - return new SizeFieldMapper(enabled, fieldType, provider); + return new SizeFieldMapper(enabled, fieldType, provider, fieldDataSettings); } } @@ -95,12 +97,12 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper { private final boolean enabled; public SizeFieldMapper() { - this(Defaults.ENABLED, new FieldType(Defaults.SIZE_FIELD_TYPE), null); + this(Defaults.ENABLED, new FieldType(Defaults.SIZE_FIELD_TYPE), null, null); } - public SizeFieldMapper(boolean enabled, FieldType fieldType, PostingsFormatProvider provider) { + public SizeFieldMapper(boolean enabled, FieldType fieldType, PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, - Defaults.BOOST, fieldType, Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED, provider, null); + Defaults.BOOST, fieldType, Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED, provider, null, fieldDataSettings); this.enabled = enabled; } 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 c06d8cdbfb8..589ce5b7d9c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java @@ -25,7 +25,6 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -201,7 +200,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.FIELD_TYPE), - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, null, null); // Only stored. + Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, null, null, null); // Only stored. this.enabled = enabled; this.compress = compress; this.compressThreshold = compressThreshold; @@ -221,8 +220,8 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In } @Override - public FieldDataType fieldDataType() { - throw new ElasticSearchIllegalArgumentException("field data on _source field is not supported"); + public FieldDataType defaultFieldDataType() { + return null; } @Override 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 cefec88a58b..c68cda4dc71 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java @@ -22,7 +22,9 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.elasticsearch.common.Explicit; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -83,7 +85,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R @Override public TTLFieldMapper build(BuilderContext context) { - return new TTLFieldMapper(fieldType, enabled, defaultTTL, ignoreMalformed(context), provider); + return new TTLFieldMapper(fieldType, enabled, defaultTTL, ignoreMalformed(context), provider, fieldDataSettings); } } @@ -112,14 +114,14 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R private long defaultTTL; public TTLFieldMapper() { - this(new FieldType(Defaults.TTL_FIELD_TYPE), Defaults.ENABLED, Defaults.DEFAULT, Defaults.IGNORE_MALFORMED, null); + this(new FieldType(Defaults.TTL_FIELD_TYPE), Defaults.ENABLED, Defaults.DEFAULT, Defaults.IGNORE_MALFORMED, null, null); } protected TTLFieldMapper(FieldType fieldType, boolean enabled, long defaultTTL, Explicit ignoreMalformed, - PostingsFormatProvider provider) { + PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.BOOST, fieldType, Defaults.NULL_VALUE, ignoreMalformed, - provider, null); + provider, null, fieldDataSettings); this.enabled = enabled; this.defaultTTL = defaultTTL; } 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 62c4bf64c3e..f5e0b2dcd6d 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java @@ -22,9 +22,11 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.elasticsearch.common.Explicit; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.mapper.*; @@ -98,7 +100,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE); } return new TimestampFieldMapper(fieldType, enabled, path, dateTimeFormatter, parseUpperInclusive, - ignoreMalformed(context), provider); + ignoreMalformed(context), provider, fieldDataSettings); } } @@ -129,16 +131,16 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap public TimestampFieldMapper() { this(new FieldType(Defaults.FIELD_TYPE), Defaults.ENABLED, Defaults.PATH, Defaults.DATE_TIME_FORMATTER, - Defaults.PARSE_UPPER_INCLUSIVE, Defaults.IGNORE_MALFORMED, null); + Defaults.PARSE_UPPER_INCLUSIVE, Defaults.IGNORE_MALFORMED, null, null); } protected TimestampFieldMapper(FieldType fieldType, boolean enabled, String path, FormatDateTimeFormatter dateTimeFormatter, boolean parseUpperInclusive, - Explicit ignoreMalformed, PostingsFormatProvider provider) { + Explicit ignoreMalformed, PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), dateTimeFormatter, Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.BOOST, fieldType, Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/, - parseUpperInclusive, ignoreMalformed, provider, null); + parseUpperInclusive, ignoreMalformed, provider, null, fieldDataSettings); this.enabled = enabled; this.path = path; } 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 09d8187de8f..60f21f8049f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.fielddata.FieldDataType; @@ -78,7 +79,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte @Override public TypeFieldMapper build(BuilderContext context) { - return new TypeFieldMapper(name, indexName, boost, fieldType, provider); + return new TypeFieldMapper(name, indexName, boost, fieldType, provider, fieldDataSettings); } } @@ -97,12 +98,12 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte } protected TypeFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), null); + this(name, indexName, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), null, null); } - public TypeFieldMapper(String name, String indexName, float boost, FieldType fieldType, PostingsFormatProvider provider) { + public TypeFieldMapper(String name, String indexName, float boost, FieldType fieldType, PostingsFormatProvider provider, @Nullable Settings fieldDataSettings) { super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER, - Lucene.KEYWORD_ANALYZER, provider, null); + Lucene.KEYWORD_ANALYZER, provider, null, fieldDataSettings); } @Override @@ -111,7 +112,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte } @Override - public FieldDataType fieldDataType() { + public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); } 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 fdf8b7ff495..711d42dab4e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -26,7 +26,6 @@ import org.apache.lucene.index.Term; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.uid.UidField; -import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.fielddata.FieldDataType; @@ -120,7 +119,7 @@ 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.FIELD_TYPE), - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null); + Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER, postingsFormat, null, null); } @Override @@ -129,8 +128,8 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal } @Override - public FieldDataType fieldDataType() { - return new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes")); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("string"); } @Override 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 4d43435c45b..0f062f411cf 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java @@ -30,12 +30,14 @@ import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericAnalyzer; import org.elasticsearch.index.analysis.NumericTokenizer; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; +import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.mapper.*; @@ -114,7 +116,7 @@ public class IpFieldMapper extends NumberFieldMapper { public IpFieldMapper build(BuilderContext context) { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); IpFieldMapper fieldMapper = new IpFieldMapper(buildNames(context), - precisionStep, boost, fieldType, nullValue, ignoreMalformed(context), provider, similarity); + precisionStep, boost, fieldType, nullValue, ignoreMalformed(context), provider, similarity, fieldDataSettings); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -141,10 +143,10 @@ public class IpFieldMapper extends NumberFieldMapper { protected IpFieldMapper(Names names, int precisionStep, float boost, FieldType fieldType, String nullValue, Explicit ignoreMalformed, - PostingsFormatProvider provider, SimilarityProvider similarity) { + PostingsFormatProvider provider, SimilarityProvider similarity, @Nullable Settings fieldDataSettings) { super(names, precisionStep, null, boost, fieldType, ignoreMalformed, new NamedAnalyzer("_ip/" + precisionStep, new NumericIpAnalyzer(precisionStep)), - new NamedAnalyzer("_ip/max", new NumericIpAnalyzer(Integer.MAX_VALUE)), provider, similarity); + new NamedAnalyzer("_ip/max", new NumericIpAnalyzer(Integer.MAX_VALUE)), provider, similarity, fieldDataSettings); this.nullValue = nullValue; } @@ -154,8 +156,8 @@ public class IpFieldMapper extends NumberFieldMapper { } @Override - public org.elasticsearch.index.fielddata.FieldDataType fieldDataType() { - return new org.elasticsearch.index.fielddata.FieldDataType("long"); + public FieldDataType defaultFieldDataType() { + return new FieldDataType("long"); } @Override