From 53f65d8ff27e0476c59fd9e7312d5d851aa74f99 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 10 Aug 2012 15:18:01 +0200 Subject: [PATCH] Remove / deprecated omit_term_freq_and_positions in favor of IndexOptions exposed via mapping API --- .../index/mapper/FieldMapper.java | 3 +- .../mapper/core/AbstractFieldMapper.java | 50 ++++++++++++------- .../index/mapper/core/BinaryFieldMapper.java | 3 +- .../index/mapper/core/BooleanFieldMapper.java | 15 +++--- .../index/mapper/core/ByteFieldMapper.java | 13 ++--- .../index/mapper/core/DateFieldMapper.java | 12 +++-- .../index/mapper/core/DoubleFieldMapper.java | 12 +++-- .../index/mapper/core/FloatFieldMapper.java | 12 +++-- .../index/mapper/core/IntegerFieldMapper.java | 12 +++-- .../index/mapper/core/LongFieldMapper.java | 12 +++-- .../index/mapper/core/NumberFieldMapper.java | 9 ++-- .../index/mapper/core/ShortFieldMapper.java | 12 +++-- .../index/mapper/core/StringFieldMapper.java | 16 +++--- .../index/mapper/core/TypeParsers.java | 25 +++++++++- .../index/mapper/geo/GeoPointFieldMapper.java | 11 ++-- .../index/mapper/internal/AllFieldMapper.java | 11 ++-- .../mapper/internal/BoostFieldMapper.java | 9 ++-- .../index/mapper/internal/IdFieldMapper.java | 15 +++--- .../mapper/internal/IndexFieldMapper.java | 15 +++--- .../mapper/internal/ParentFieldMapper.java | 5 +- .../mapper/internal/RoutingFieldMapper.java | 7 +-- .../mapper/internal/SizeFieldMapper.java | 2 +- .../mapper/internal/SourceFieldMapper.java | 5 +- .../index/mapper/internal/TTLFieldMapper.java | 4 +- .../mapper/internal/TimestampFieldMapper.java | 4 +- .../mapper/internal/TypeFieldMapper.java | 15 +++--- .../index/mapper/internal/UidFieldMapper.java | 3 +- .../index/mapper/ip/IpFieldMapper.java | 12 +++-- .../search/query/SimpleQueryTests.java | 46 +++++++++++++++++ 29 files changed, 239 insertions(+), 131 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index 7f196b3433c..af1655d0d16 100644 --- a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.Filter; import org.apache.lucene.search.MultiTermQuery; @@ -135,7 +136,7 @@ public interface FieldMapper { boolean omitNorms(); - boolean omitTermFreqAndPositions(); + IndexOptions indexOptions(); /** * The analyzer that will be used to index the field. 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 64266f16160..9ba39a0643e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -23,8 +23,10 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.*; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.TermFilter; @@ -47,7 +49,7 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { public static final Field.TermVector TERM_VECTOR = Field.TermVector.NO; public static final float BOOST = 1.0f; public static final boolean OMIT_NORMS = false; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = false; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; } public abstract static class OpenBuilder extends AbstractFieldMapper.Builder { @@ -82,8 +84,8 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { } @Override - public T omitTermFreqAndPositions(boolean omitTermFreqAndPositions) { - return super.omitTermFreqAndPositions(omitTermFreqAndPositions); + public T indexOptions(IndexOptions indexOptions) { + return super.indexOptions(indexOptions); } @Override @@ -113,9 +115,7 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected float boost = Defaults.BOOST; protected boolean omitNorms = Defaults.OMIT_NORMS; - - protected boolean omitTermFreqAndPositions = Defaults.OMIT_TERM_FREQ_AND_POSITIONS; - + protected String indexName; protected NamedAnalyzer indexAnalyzer; @@ -124,6 +124,8 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected Boolean includeInAll; + protected IndexOptions indexOptions = Defaults.INDEX_OPTIONS; + protected Builder(String name) { super(name); } @@ -152,12 +154,12 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { this.omitNorms = omitNorms; return builder; } - - protected T omitTermFreqAndPositions(boolean omitTermFreqAndPositions) { - this.omitTermFreqAndPositions = omitTermFreqAndPositions; + + protected T indexOptions(IndexOptions indexOptions) { + this.indexOptions = indexOptions; return builder; } - + protected T indexName(String indexName) { this.indexName = indexName; return builder; @@ -206,8 +208,7 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected float boost; protected final boolean omitNorms; - - protected final boolean omitTermFreqAndPositions; + protected final FieldInfo.IndexOptions indexOptions; protected final NamedAnalyzer indexAnalyzer; @@ -215,15 +216,15 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { protected final NamedAnalyzer searchAnalyzer; protected AbstractFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { + float boost, boolean omitNorms, IndexOptions indexOptions, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { this.names = names; this.index = index; this.store = store; this.termVector = termVector; this.boost = boost; this.omitNorms = omitNorms; - this.omitTermFreqAndPositions = omitTermFreqAndPositions; - this.indexOptions = omitTermFreqAndPositions ? FieldInfo.IndexOptions.DOCS_ONLY : FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; + this.indexOptions = indexOptions; + // automatically set to keyword analyzer if its indexed and not analyzed if (indexAnalyzer == null && !index.isAnalyzed() && index.isIndexed()) { this.indexAnalyzer = Lucene.KEYWORD_ANALYZER; @@ -287,10 +288,10 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { public boolean omitNorms() { return this.omitNorms; } - + @Override - public boolean omitTermFreqAndPositions() { - return this.omitTermFreqAndPositions; + public IndexOptions indexOptions() { + return this.indexOptions; } @Override @@ -479,6 +480,19 @@ public abstract class AbstractFieldMapper implements FieldMapper, Mapper { builder.endObject(); return builder; } + + protected static String indexOptionToString(IndexOptions indexOption) { + switch (indexOption) { + case DOCS_AND_FREQS: + return TypeParsers.INDEX_OPTIONS_FREQS; + case DOCS_AND_FREQS_AND_POSITIONS: + return TypeParsers.INDEX_OPTIONS_POSITIONS; + case DOCS_ONLY: + return TypeParsers.INDEX_OPTIONS_DOCS; + default: + throw new ElasticSearchIllegalArgumentException("Unknown IndexOptions [" + indexOption + "]"); + } + } protected void doXContentBody(XContentBuilder builder) throws IOException { builder.field("type", 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 b51726bdfb5..b159364c018 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BinaryFieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Base64; import org.elasticsearch.common.Strings; @@ -114,7 +115,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper { private long compressThreshold; protected BinaryFieldMapper(Names names, Field.Store store, Boolean compress, long compressThreshold) { - super(names, Field.Index.NO, store, Field.TermVector.NO, 1.0f, true, true, null, null); + super(names, Field.Index.NO, store, Field.TermVector.NO, 1.0f, true, IndexOptions.DOCS_ONLY, null, null); this.compress = compress; this.compressThreshold = compressThreshold; } 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 5d1fc3048dd..fceefaafbc1 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Strings; @@ -92,15 +93,11 @@ public class BooleanFieldMapper extends AbstractFieldMapper { return super.indexName(indexName); } - @Override - public Builder omitTermFreqAndPositions(boolean omitTermFreqAndPositions) { - return super.omitTermFreqAndPositions(omitTermFreqAndPositions); - } @Override public BooleanFieldMapper build(BuilderContext context) { return new BooleanFieldMapper(buildNames(context), index, store, - termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue); + termVector, boost, omitNorms, indexOptions, nullValue); } } @@ -123,8 +120,8 @@ public class BooleanFieldMapper extends AbstractFieldMapper { private Boolean nullValue; protected BooleanFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, Boolean nullValue) { - super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + float boost, boolean omitNorms, IndexOptions indexOptions, Boolean nullValue) { + super(names, index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); this.nullValue = nullValue; } @@ -210,8 +207,8 @@ public class BooleanFieldMapper extends AbstractFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } 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 2da1c1d9cf3..f82b11f04ac 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ByteFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -74,8 +76,7 @@ public class ByteFieldMapper extends NumberFieldMapper { @Override public ByteFieldMapper build(BuilderContext context) { ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, - omitTermFreqAndPositions, nullValue, ignoreMalformed); + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -102,9 +103,9 @@ public class ByteFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected ByteFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Byte nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_byte/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), new NamedAnalyzer("_byte/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -323,8 +324,8 @@ public class ByteFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 f2a4a308b49..404114731d2 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -40,6 +41,7 @@ import org.elasticsearch.index.analysis.NumericDateAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -102,7 +104,7 @@ public class DateFieldMapper extends NumberFieldMapper { parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE); } DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter, - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, timeUnit, parseUpperInclusive, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -141,9 +143,9 @@ public class DateFieldMapper extends NumberFieldMapper { protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue, TimeUnit timeUnit, boolean parseUpperInclusive, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_date/" + precisionStep, new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())), new NamedAnalyzer("_date/max", new NumericDateAnalyzer(Integer.MAX_VALUE, dateTimeFormatter.parser()))); @@ -395,8 +397,8 @@ public class DateFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 bdd271b835d..ec244b8450f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/DoubleFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericDoubleAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -74,7 +76,7 @@ public class DoubleFieldMapper extends NumberFieldMapper { @Override public DoubleFieldMapper build(BuilderContext context) { DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -104,9 +106,9 @@ public class DoubleFieldMapper extends NumberFieldMapper { protected DoubleFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Double nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_double/" + precisionStep, new NumericDoubleAnalyzer(precisionStep)), new NamedAnalyzer("_double/max", new NumericDoubleAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -325,8 +327,8 @@ public class DoubleFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 bfa31002894..8215d91fa8c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/FloatFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -37,6 +38,7 @@ import org.elasticsearch.index.analysis.NumericFloatAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -75,7 +77,7 @@ public class FloatFieldMapper extends NumberFieldMapper { @Override public FloatFieldMapper build(BuilderContext context) { FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -103,9 +105,9 @@ public class FloatFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected FloatFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Float nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)), new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -321,8 +323,8 @@ public class FloatFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 233e28829f3..b3d6992c805 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/IntegerFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -37,6 +38,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -75,7 +77,7 @@ public class IntegerFieldMapper extends NumberFieldMapper { @Override public IntegerFieldMapper build(BuilderContext context) { IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -103,9 +105,9 @@ public class IntegerFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected IntegerFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Integer nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_int/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), new NamedAnalyzer("_int/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -325,8 +327,8 @@ public class IntegerFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 f3c8d9b2879..7d7a4a95b64 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/LongFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -37,6 +38,7 @@ import org.elasticsearch.index.analysis.NumericLongAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -75,7 +77,7 @@ public class LongFieldMapper extends NumberFieldMapper { @Override public LongFieldMapper build(BuilderContext context) { LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -103,9 +105,9 @@ public class LongFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected LongFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Long nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_long/" + precisionStep, new NumericLongAnalyzer(precisionStep)), new NamedAnalyzer("_long/max", new NumericLongAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -324,8 +326,8 @@ public class LongFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 aa50501b07a..0e44d50c666 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/NumberFieldMapper.java @@ -24,6 +24,7 @@ import org.apache.lucene.document.AbstractField; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.util.NumericUtils; @@ -48,7 +49,7 @@ public abstract class NumberFieldMapper extends AbstractFieldM public static final int PRECISION_STEP = NumericUtils.PRECISION_STEP_DEFAULT; public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; public static final String FUZZY_FACTOR = null; public static final boolean IGNORE_MALFORMED = false; } @@ -65,7 +66,7 @@ public abstract class NumberFieldMapper extends AbstractFieldM super(name); this.index = Defaults.INDEX; this.omitNorms = Defaults.OMIT_NORMS; - this.omitTermFreqAndPositions = Defaults.OMIT_TERM_FREQ_AND_POSITIONS; + this.indexOptions = Defaults.INDEX_OPTIONS; } @Override @@ -124,9 +125,9 @@ public abstract class NumberFieldMapper extends AbstractFieldM protected NumberFieldMapper(Names names, int precisionStep, @Nullable String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, boolean ignoreMalformed, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { - super(names, index, store, Field.TermVector.NO, boost, boost != 1.0f || omitNorms, omitTermFreqAndPositions, indexAnalyzer, searchAnalyzer); + super(names, index, store, Field.TermVector.NO, boost, boost != 1.0f || omitNorms, indexOptions, indexAnalyzer, searchAnalyzer); 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 63ebd15d61f..12bfc2487a1 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/ShortFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -37,6 +38,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -75,7 +77,7 @@ public class ShortFieldMapper extends NumberFieldMapper { @Override public ShortFieldMapper build(BuilderContext context) { ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context), - precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, + precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -103,9 +105,9 @@ public class ShortFieldMapper extends NumberFieldMapper { private String nullValueAsString; protected ShortFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Short nullValue, boolean ignoreMalformed) { - super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, ignoreMalformed, new NamedAnalyzer("_short/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)), new NamedAnalyzer("_short/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -324,8 +326,8 @@ public class ShortFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); 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 32da8045082..17cc5e6ac1f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -30,6 +31,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NamedCustomAnalyzer; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.mapper.internal.AllFieldMapper; import java.io.IOException; @@ -110,7 +112,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al searchQuotedAnalyzer = new NamedCustomAnalyzer(searchQuotedAnalyzer, positionOffsetGap); } StringFieldMapper fieldMapper = new StringFieldMapper(buildNames(context), - index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, + index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer, searchAnalyzer, searchQuotedAnalyzer, positionOffsetGap, ignoreAbove); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -165,17 +167,17 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al private int ignoreAbove; protected StringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { - this(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, + this(names, index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer, searchAnalyzer, searchAnalyzer, Defaults.POSITION_OFFSET_GAP, Defaults.IGNORE_ABOVE); } protected StringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, NamedAnalyzer searchQuotedAnalyzer, int positionOffsetGap, int ignoreAbove) { - super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, indexAnalyzer, searchAnalyzer); + super(names, index, store, termVector, boost, omitNorms, indexOptions, indexAnalyzer, searchAnalyzer); this.nullValue = nullValue; this.positionOffsetGap = positionOffsetGap; this.searchQuotedAnalyzer = searchQuotedAnalyzer != null ? searchQuotedAnalyzer : this.searchAnalyzer; @@ -317,8 +319,8 @@ public class StringFieldMapper extends AbstractFieldMapper implements Al if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (nullValue != null) { builder.field("null_value", nullValue); 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 684ce034646..2bcdf14eec1 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java @@ -20,6 +20,9 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; +import org.apache.lucene.document.Field.Index; +import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; @@ -36,6 +39,10 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.*; * */ public class TypeParsers { + + public static final String INDEX_OPTIONS_DOCS = "docs"; + public static final String INDEX_OPTIONS_FREQS = "freqs"; + public static final String INDEX_OPTIONS_POSITIONS = "positions"; public static void parseNumberField(NumberFieldMapper.Builder builder, String name, Map numberNode, Mapper.TypeParser.ParserContext parserContext) { parseField(builder, name, numberNode, parserContext); @@ -69,7 +76,10 @@ public class TypeParsers { } else if (propName.equals("omit_norms")) { builder.omitNorms(nodeBooleanValue(propNode)); } else if (propName.equals("omit_term_freq_and_positions")) { - builder.omitTermFreqAndPositions(nodeBooleanValue(propNode)); + // deprecated option for BW compat + builder.indexOptions(nodeBooleanValue(propNode) ? IndexOptions.DOCS_ONLY : IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); + } else if (propName.equals("index_options")) { + builder.indexOptions(nodeIndexOptionValue(propNode)); } else if (propName.equals("analyzer")) { NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); if (analyzer == null) { @@ -95,6 +105,19 @@ public class TypeParsers { } } + private static IndexOptions nodeIndexOptionValue(final Object propNode) { + final String value = propNode.toString(); + if (INDEX_OPTIONS_POSITIONS.equalsIgnoreCase(value)) { + return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; + } else if (INDEX_OPTIONS_FREQS.equalsIgnoreCase(value)) { + return IndexOptions.DOCS_AND_FREQS; + } else if (INDEX_OPTIONS_DOCS.equalsIgnoreCase(value)) { + return IndexOptions.DOCS_ONLY; + } else { + throw new ElasticSearchParseException("Failed to parse index option [" + value + "]"); + } + } + public static FormatDateTimeFormatter parseDateTimeFormatter(String fieldName, Object node) { return Joda.forPattern(node.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 66d22336456..5287f9ce75f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper.geo; import org.apache.lucene.document.Field; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -142,7 +143,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { context.path().pathType(pathType); GeoStringFieldMapper geoStringMapper = new GeoStringFieldMapper.Builder(name) - .index(Field.Index.NOT_ANALYZED).omitNorms(true).omitTermFreqAndPositions(true).includeInAll(false).store(store).build(context); + .index(Field.Index.NOT_ANALYZED).omitNorms(true).indexOptions(IndexOptions.DOCS_ONLY).includeInAll(false).store(store).build(context); DoubleFieldMapper latMapper = null; @@ -161,7 +162,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { } StringFieldMapper geohashMapper = null; if (enableGeoHash) { - geohashMapper = stringField(Names.GEOHASH).index(Field.Index.NOT_ANALYZED).includeInAll(false).omitNorms(true).omitTermFreqAndPositions(true).build(context); + geohashMapper = stringField(Names.GEOHASH).index(Field.Index.NOT_ANALYZED).includeInAll(false).omitNorms(true).indexOptions(IndexOptions.DOCS_ONLY).build(context); } context.path().remove(); @@ -551,7 +552,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { @Override public GeoStringFieldMapper build(BuilderContext context) { GeoStringFieldMapper fieldMapper = new GeoStringFieldMapper(buildNames(context), - index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, + index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer, searchAnalyzer); fieldMapper.includeInAll(includeInAll); return fieldMapper; @@ -560,8 +561,8 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser { GeoPointFieldMapper geoMapper; - public GeoStringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { - super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, searchAnalyzer); + public GeoStringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) { + super(names, index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer, searchAnalyzer); } @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 a44b3f4caae..ffd825e1c2b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.elasticsearch.common.Strings; @@ -100,7 +101,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna @Override public AllFieldMapper build(BuilderContext context) { - return new AllFieldMapper(name, store, termVector, omitNorms, omitTermFreqAndPositions, + return new AllFieldMapper(name, store, termVector, omitNorms, indexOptions, indexAnalyzer, searchAnalyzer, enabled); } } @@ -125,13 +126,13 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna private boolean enabled; public AllFieldMapper() { - this(Defaults.NAME, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, null, null, Defaults.ENABLED); + this(Defaults.NAME, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, null, null, Defaults.ENABLED); } - protected AllFieldMapper(String name, Field.Store store, Field.TermVector termVector, boolean omitNorms, boolean omitTermFreqAndPositions, + protected AllFieldMapper(String name, Field.Store store, Field.TermVector termVector, boolean omitNorms, IndexOptions indexOptions, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, boolean enabled) { - super(new Names(name, name, name, name), Field.Index.ANALYZED, store, termVector, 1.0f, omitNorms, omitTermFreqAndPositions, - indexAnalyzer, searchAnalyzer); + super(new Names(name, name, name, name), Field.Index.ANALYZED, store, termVector, 1.0f, omitNorms, indexOptions, indexAnalyzer, + searchAnalyzer); this.enabled = enabled; } 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 a46cdacc6de..fb3a91048e0 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.Filter; import org.apache.lucene.search.NumericRangeFilter; import org.apache.lucene.search.NumericRangeQuery; @@ -81,7 +82,7 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern @Override public BoostFieldMapper build(BuilderContext context) { return new BoostFieldMapper(name, buildIndexName(context), - precisionStep, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue); + precisionStep, index, store, boost, omitNorms, indexOptions, nullValue); } } @@ -110,13 +111,13 @@ public class BoostFieldMapper extends NumberFieldMapper implements Intern protected BoostFieldMapper(String name, String indexName) { this(name, indexName, Defaults.PRECISION_STEP, Defaults.INDEX, Defaults.STORE, - Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE); + Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.NULL_VALUE); } protected BoostFieldMapper(String name, String indexName, int precisionStep, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, Float nullValue) { - super(new Names(name, indexName, indexName, name), precisionStep, null, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(new Names(name, indexName, indexName, name), precisionStep, null, index, store, boost, omitNorms, indexOptions, false, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)), new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; 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 e7e6c0a6933..d20b47dc267 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java @@ -24,6 +24,7 @@ import com.google.common.collect.Iterables; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.*; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -58,7 +59,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern public static final Field.Index INDEX = Field.Index.NO; public static final Field.Store STORE = Field.Store.NO; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; public static final String PATH = null; } @@ -72,7 +73,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern store = Defaults.STORE; index = Defaults.INDEX; omitNorms = Defaults.OMIT_NORMS; - omitTermFreqAndPositions = Defaults.OMIT_TERM_FREQ_AND_POSITIONS; + indexOptions = Defaults.INDEX_OPTIONS; } public Builder path(String path) { @@ -82,7 +83,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern @Override public IdFieldMapper build(BuilderContext context) { - return new IdFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, path); + return new IdFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, indexOptions, path); } } @@ -114,13 +115,13 @@ public class IdFieldMapper extends AbstractFieldMapper implements Intern protected IdFieldMapper(String name, String indexName, Field.Index index) { this(name, indexName, index, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.PATH); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.PATH); } protected IdFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String path) { - super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + float boost, boolean omitNorms, IndexOptions indexOptions, String path) { + super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER, + Lucene.KEYWORD_ANALYZER); this.path = 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 84adc02c699..f7765276a33 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.Term; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -50,7 +51,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final Field.Store STORE = Field.Store.NO; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; public static final boolean ENABLED = false; } @@ -64,7 +65,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int index = Defaults.INDEX; store = Defaults.STORE; omitNorms = Defaults.OMIT_NORMS; - omitTermFreqAndPositions = Defaults.OMIT_TERM_FREQ_AND_POSITIONS; + indexOptions = Defaults.INDEX_OPTIONS; } public Builder enabled(boolean enabled) { @@ -74,7 +75,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int @Override public IndexFieldMapper build(BuilderContext context) { - return new IndexFieldMapper(name, indexName, store, termVector, boost, omitNorms, omitTermFreqAndPositions, enabled); + return new IndexFieldMapper(name, indexName, store, termVector, boost, omitNorms, indexOptions, enabled); } } @@ -103,13 +104,13 @@ public class IndexFieldMapper extends AbstractFieldMapper implements Int protected IndexFieldMapper(String name, String indexName) { this(name, indexName, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.ENABLED); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.ENABLED); } public IndexFieldMapper(String name, String indexName, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, boolean enabled) { - super(new Names(name, indexName, indexName, name), Defaults.INDEX, store, termVector, boost, omitNorms, omitTermFreqAndPositions, - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + float boost, boolean omitNorms, IndexOptions indexOptions, boolean enabled) { + super(new Names(name, indexName, indexName, name), Defaults.INDEX, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER, + Lucene.KEYWORD_ANALYZER); this.enabled = 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 1147fa7730b..e846a6e47ff 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Filter; @@ -50,7 +51,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter public static final String NAME = ParentFieldMapper.NAME; public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; } public static class Builder extends Mapper.Builder { @@ -97,7 +98,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements Inter protected ParentFieldMapper(String name, String indexName, String type) { super(new Names(name, indexName, indexName, name), Defaults.INDEX, Field.Store.YES, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); this.type = type; } 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 604953bb228..8435027ac10 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/RoutingFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -49,7 +50,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final Field.Store STORE = Field.Store.YES; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; public static final boolean REQUIRED = false; public static final String PATH = null; } @@ -110,8 +111,8 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements I } protected RoutingFieldMapper(Field.Store store, Field.Index index, boolean required, String path) { - super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), index, store, Defaults.TERM_VECTOR, 1.0f, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), index, store, Defaults.TERM_VECTOR, 1.0f, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, + Lucene.KEYWORD_ANALYZER); this.required = required; this.path = path; } 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 bc45250d4ac..f6203ef21c2 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SizeFieldMapper.java @@ -94,7 +94,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper { public SizeFieldMapper(boolean enabled, Field.Store store) { super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.INDEX, store, - Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, + Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED); 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 36fdc09cfb9..b818f99b285 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java @@ -23,6 +23,7 @@ import com.google.common.base.Objects; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -69,7 +70,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements In public static final Field.Index INDEX = Field.Index.NO; public static final Field.Store STORE = Field.Store.YES; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; public static final String[] INCLUDES = Strings.EMPTY_ARRAY; public static final String[] EXCLUDES = Strings.EMPTY_ARRAY; } @@ -190,7 +191,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.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); this.enabled = enabled; this.compress = compress; this.compressThreshold = compressThreshold; 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 e8957a0fc68..e175e83f247 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java @@ -109,8 +109,8 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R protected TTLFieldMapper(Field.Store store, Field.Index index, boolean enabled, long defaultTTL) { super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), Defaults.PRECISION_STEP, - Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, - Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED); + Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, + Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED); 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 c9fe689f13e..467ab3f5357 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TimestampFieldMapper.java @@ -124,8 +124,8 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap protected TimestampFieldMapper(Field.Store store, Field.Index index, boolean enabled, String path, FormatDateTimeFormatter dateTimeFormatter, boolean parseUpperInclusive) { super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), dateTimeFormatter, - Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, - Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/, + Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, + Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/, parseUpperInclusive, Defaults.IGNORE_MALFORMED); 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 f75eaa8c4ee..59d232bfec8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.search.DeletionAwareConstantScoreQuery; import org.apache.lucene.search.Filter; @@ -58,7 +59,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final Field.Store STORE = Field.Store.NO; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true; + public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY; } public static class Builder extends AbstractFieldMapper.Builder { @@ -69,12 +70,12 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte index = Defaults.INDEX; store = Defaults.STORE; omitNorms = Defaults.OMIT_NORMS; - omitTermFreqAndPositions = Defaults.OMIT_TERM_FREQ_AND_POSITIONS; + indexOptions = Defaults.INDEX_OPTIONS; } @Override public TypeFieldMapper build(BuilderContext context) { - return new TypeFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions); + return new TypeFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, indexOptions); } } @@ -94,13 +95,13 @@ public class TypeFieldMapper extends AbstractFieldMapper implements Inte protected TypeFieldMapper(String name, String indexName) { this(name, indexName, Defaults.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS); } public TypeFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { - super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, - Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + float boost, boolean omitNorms, IndexOptions indexOptions) { + super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER, + Lucene.KEYWORD_ANALYZER); } public String value(Document document) { 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 cf5a7aebf6d..abbd8213e04 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -48,7 +48,6 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal public static final String NAME = UidFieldMapper.NAME; public static final Field.Index INDEX = Field.Index.NOT_ANALYZED; public static final boolean OMIT_NORMS = true; - public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = false; // we store payload } public static class Builder extends Mapper.Builder { @@ -90,7 +89,7 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal protected UidFieldMapper(String name, String indexName) { super(new Names(name, indexName, indexName, name), Defaults.INDEX, Field.Store.YES, Defaults.TERM_VECTOR, Defaults.BOOST, - Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); + Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); } @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 70e4e206a90..70047a19471 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.ip; import org.apache.lucene.analysis.NumericTokenStream; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.*; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.ElasticSearchIllegalArgumentException; @@ -38,6 +39,7 @@ import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.core.LongFieldMapper; import org.elasticsearch.index.mapper.core.NumberFieldMapper; +import org.elasticsearch.index.mapper.core.BooleanFieldMapper.Defaults; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.search.NumericRangeFieldDataFilter; @@ -103,7 +105,7 @@ public class IpFieldMapper extends NumberFieldMapper { @Override public IpFieldMapper build(BuilderContext context) { IpFieldMapper fieldMapper = new IpFieldMapper(buildNames(context), - precisionStep, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue); + precisionStep, index, store, boost, omitNorms, indexOptions, nullValue); fieldMapper.includeInAll(includeInAll); return fieldMapper; } @@ -129,9 +131,9 @@ public class IpFieldMapper extends NumberFieldMapper { protected IpFieldMapper(Names names, int precisionStep, Field.Index index, Field.Store store, - float boost, boolean omitNorms, boolean omitTermFreqAndPositions, + float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue) { - super(names, precisionStep, null, index, store, boost, omitNorms, omitTermFreqAndPositions, + super(names, precisionStep, null, index, store, boost, omitNorms, indexOptions, false, new NamedAnalyzer("_ip/" + precisionStep, new NumericIpAnalyzer(precisionStep)), new NamedAnalyzer("_ip/max", new NumericIpAnalyzer(Integer.MAX_VALUE))); this.nullValue = nullValue; @@ -301,8 +303,8 @@ public class IpFieldMapper extends NumberFieldMapper { if (omitNorms != Defaults.OMIT_NORMS) { builder.field("omit_norms", omitNorms); } - if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) { - builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions); + if (indexOptions != Defaults.INDEX_OPTIONS) { + builder.field("index_options", indexOptionToString(indexOptions)); } if (precisionStep != Defaults.PRECISION_STEP) { builder.field("precision_step", precisionStep); diff --git a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java index e1edb39b03c..98e753c3e66 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.integration.search.query; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; @@ -33,6 +34,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.*; @@ -81,6 +84,49 @@ public class SimpleQueryTests extends AbstractNodesTests { SearchResponse searchResponse = client.prepareSearch().setQuery("{ \"term\" : { \"field1\" : \"value1_1\" }}").execute().actionGet(); assertThat(searchResponse.hits().totalHits(), equalTo(1l)); } + + @Test + public void testIndexOptions() throws Exception { + try { + client.admin().indices().prepareDelete("test").execute().actionGet(); + } catch (Exception e) { + // ignore + } + + client.admin().indices().prepareCreate("test") + .addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("index_options", "docs").field("type", "string").endObject().endObject().endObject().endObject()) + .setSettings(ImmutableSettings.settingsBuilder().put("number_of_shards", 1)).execute().actionGet(); + + client.prepareIndex("test", "type1", "1").setSource("field1", "quick brown fox", "field2", "quick brown fox").execute().actionGet(); + client.prepareIndex("test", "type1", "2").setSource("field1", "quick lazy huge brown fox", "field2", "quick lazy huge brown fox").setRefresh(true).execute().actionGet(); + + SearchResponse searchResponse = client.prepareSearch().setQuery("{ \"text_phrase\" : { \"field2\" : \"quick brown\", \"slop\" : \"2\" }}").execute().actionGet(); + assertThat(searchResponse.hits().totalHits(), equalTo(1l)); + SearchResponse actionGet = client.prepareSearch().setQuery("{ \"text_phrase\" : { \"field1\" : \"quick brown\", \"slop\" : \"2\" }}").execute().actionGet(); + assertThat(actionGet.hits().totalHits(), equalTo(0l)); + } + + @Test + public void testOmitTermFreqsAndPositions() throws Exception { + // backwards compat test! + try { + client.admin().indices().prepareDelete("test").execute().actionGet(); + } catch (Exception e) { + // ignore + } + + client.admin().indices().prepareCreate("test") + .addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("omit_term_freq_and_positions", true).field("type", "string").endObject().endObject().endObject().endObject()) + .setSettings(ImmutableSettings.settingsBuilder().put("number_of_shards", 1)).execute().actionGet(); + + client.prepareIndex("test", "type1", "1").setSource("field1", "quick brown fox", "field2", "quick brown fox").execute().actionGet(); + client.prepareIndex("test", "type1", "2").setSource("field1", "quick lazy huge brown fox", "field2", "quick lazy huge brown fox").setRefresh(true).execute().actionGet(); + + SearchResponse searchResponse = client.prepareSearch().setQuery("{ \"text_phrase\" : { \"field2\" : \"quick brown\", \"slop\" : \"2\" }}").execute().actionGet(); + assertThat(searchResponse.hits().totalHits(), equalTo(1l)); + SearchResponse actionGet = client.prepareSearch().setQuery("{ \"text_phrase\" : { \"field1\" : \"quick brown\", \"slop\" : \"2\" }}").execute().actionGet(); + assertThat(actionGet.hits().totalHits(), equalTo(0l)); + } @Test public void queryStringAnalyzedWildcard() throws Exception {