diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java index 42c65df5bf4..40d42be82a6 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.FeatureField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; @@ -190,7 +189,7 @@ public class RankFeatureFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { float value; if (context.externalValueSet()) { Object v = context.externalValue(); diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapper.java index 8846c2cdb74..a109248ad72 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; @@ -29,7 +28,6 @@ import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -132,7 +130,7 @@ public class RankFeatureMetaFieldMapper extends MetadataFieldMapper { public void preParse(ParseContext context) throws IOException {} @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new AssertionError("Should never be called"); } diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java index e0b08fffbb0..3d69b7af8d6 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.FeatureField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; @@ -30,7 +29,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; -import java.util.List; import java.util.Map; /** @@ -167,7 +165,7 @@ public class RankFeaturesFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new AssertionError("parse is implemented directly"); } diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index c969ee00d9f..d95684b324b 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -19,9 +19,9 @@ package org.elasticsearch.index.mapper; +import org.apache.lucene.document.Field; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedNumericDocValues; @@ -43,12 +43,12 @@ import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; @@ -64,8 +64,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.sort.BucketedSort; import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.math.BigDecimal; @@ -390,7 +388,7 @@ public class ScaledFloatFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { XContentParser parser = context.parser(); Object value; @@ -442,9 +440,11 @@ public class ScaledFloatFieldMapper extends FieldMapper { boolean indexed = fieldType().indexOptions() != IndexOptions.NONE; boolean docValued = fieldType().hasDocValues(); boolean stored = fieldType().stored(); - fields.addAll(NumberFieldMapper.NumberType.LONG.createFields(fieldType().name(), scaledValue, indexed, docValued, stored)); + List fields = NumberFieldMapper.NumberType.LONG.createFields(fieldType().name(), scaledValue, indexed, docValued, stored); + context.doc().addAll(fields); + if (docValued == false && (indexed || stored)) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java index 9a5c389dd8e..ef09d72034f 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java @@ -484,7 +484,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) { + protected void parseCreateField(ParseContext context) { throw new UnsupportedOperationException(); } @@ -511,7 +511,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) { + protected void parseCreateField(ParseContext context) { throw new UnsupportedOperationException(); } @@ -675,22 +675,21 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value = context.externalValueSet() ? context.externalValue().toString() : context.parser().textOrNull(); if (value == null) { return; } List newFields = new ArrayList<>(); - newFields.add(new Field(fieldType().name(), value, fieldType())); + context.doc().add(new Field(fieldType().name(), value, fieldType())); for (ShingleFieldMapper subFieldMapper : shingleFields) { - fields.add(new Field(subFieldMapper.fieldType().name(), value, subFieldMapper.fieldType())); + context.doc().add(new Field(subFieldMapper.fieldType().name(), value, subFieldMapper.fieldType())); } - newFields.add(new Field(prefixField.fieldType().name(), value, prefixField.fieldType())); + context.doc().add(new Field(prefixField.fieldType().name(), value, prefixField.fieldType())); if (fieldType().omitNorms()) { - createFieldNamesField(context, newFields); + createFieldNamesField(context); } - fields.addAll(newFields); } @Override diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java index 7a777963baa..1da8e5d764c 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java @@ -23,18 +23,16 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.analysis.NamedAnalyzer; import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; -import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeIntegerValue; import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue; +import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeIntegerValue; import static org.elasticsearch.index.mapper.TypeParsers.parseField; /** @@ -126,7 +124,7 @@ public class TokenCountFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -148,7 +146,7 @@ public class TokenCountFieldMapper extends FieldMapper { boolean indexed = fieldType().indexOptions() != IndexOptions.NONE; boolean docValued = fieldType().hasDocValues(); boolean stored = fieldType().stored(); - fields.addAll(NumberFieldMapper.NumberType.INTEGER.createFields(fieldType().name(), tokenCount, indexed, docValued, stored)); + context.doc().addAll(NumberFieldMapper.NumberType.INTEGER.createFields(fieldType().name(), tokenCount, indexed, docValued, stored)); } /** diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java index f1b75672ccc..72f483d3085 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.join.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.settings.Settings; @@ -35,7 +34,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; -import java.util.List; /** * Simple field mapper hack to ensure that there is a one and only {@link ParentJoinFieldMapper} per mapping. @@ -140,7 +138,7 @@ public class MetaJoinFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new IllegalStateException("Should never be called"); } diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java index 7dc43962ad9..fd0856c2266 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.join.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; @@ -46,7 +45,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.util.Collection; -import java.util.List; import java.util.Set; /** @@ -188,15 +186,15 @@ public final class ParentIdFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (context.externalValueSet() == false) { throw new IllegalStateException("external value not set"); } String refId = (String) context.externalValue(); BytesRef binaryValue = new BytesRef(refId); Field field = new Field(fieldType().name(), binaryValue, fieldType()); - fields.add(field); - fields.add(new SortedDocValuesField(fieldType().name(), binaryValue)); + context.doc().add(field); + context.doc().add(new SortedDocValuesField(fieldType().name(), binaryValue)); } diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java index 90a7dc94bf5..af1e6a733a1 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.join.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; @@ -377,7 +376,7 @@ public final class ParentJoinFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException("parsing is implemented in parse(), this method should NEVER be called"); } diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java index 0a5cb2e59c4..6f63da1a73f 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java @@ -25,7 +25,6 @@ import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.Term; @@ -473,11 +472,8 @@ public class PercolatorFieldMapper extends FieldMapper { } else { doc.add(new Field(extractionResultField.name(), EXTRACTION_PARTIAL, extractionResultField.fieldType())); } - List fields = new ArrayList<>(1); - createFieldNamesField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } + + createFieldNamesField(context); if (indexVersionCreated.onOrAfter(Version.V_6_1_0)) { doc.add(new NumericDocValuesField(minimumShouldMatchFieldMapper.name(), result.minimumShouldMatch)); } @@ -516,7 +512,7 @@ public class PercolatorFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException("should not be invoked"); } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index 57a0dba31f4..d8364fdf82f 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -26,7 +26,6 @@ import com.ibm.icu.util.ULocale; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.MultiTermQuery; @@ -735,7 +734,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -757,13 +756,13 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), binaryValue, fieldType()); - fields.add(field); + context.doc().add(field); } if (fieldType().hasDocValues()) { - fields.add(new SortedSetDocValuesField(fieldType().name(), binaryValue)); + context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue)); } else if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } } diff --git a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java index 60036511e2f..299dc670c8b 100644 --- a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java +++ b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java @@ -30,7 +30,6 @@ import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -574,7 +573,7 @@ public class AnnotatedTextFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -588,9 +587,9 @@ public class AnnotatedTextFieldMapper extends FieldMapper { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), value, fieldType()); - fields.add(field); + context.doc().add(field); if (fieldType().omitNorms()) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } } diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java index b6c49a246f4..75f45cffbfb 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper.murmur3; import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; @@ -43,7 +42,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; -import java.util.List; import java.util.Map; public class Murmur3FieldMapper extends FieldMapper { @@ -153,7 +151,7 @@ public class Murmur3FieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) + protected void parseCreateField(ParseContext context) throws IOException { final Object value; if (context.externalValueSet()) { @@ -164,9 +162,9 @@ public class Murmur3FieldMapper extends FieldMapper { if (value != null) { final BytesRef bytes = new BytesRef(value.toString()); final long hash = MurmurHash3.hash128(bytes.bytes, bytes.offset, bytes.length, 0, new MurmurHash3.Hash128()).h1; - fields.add(new SortedNumericDocValuesField(fieldType().name(), hash)); + context.doc().add(new SortedNumericDocValuesField(fieldType().name(), hash)); if (fieldType().stored()) { - fields.add(new StoredField(name(), hash)); + context.doc().add(new StoredField(name(), hash)); } } } diff --git a/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java b/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java index b2220e68b4f..ef745c73575 100644 --- a/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java +++ b/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper.size; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.Version; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; @@ -36,7 +35,6 @@ import org.elasticsearch.index.mapper.ParseContext; import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; public class SizeFieldMapper extends MetadataFieldMapper { @@ -150,7 +148,7 @@ public class SizeFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (!enabledState.enabled) { return; } @@ -158,7 +156,7 @@ public class SizeFieldMapper extends MetadataFieldMapper { boolean indexed = fieldType().indexOptions() != IndexOptions.NONE; boolean docValued = fieldType().hasDocValues(); boolean stored = fieldType().stored(); - fields.addAll(NumberFieldMapper.NumberType.INTEGER.createFields(name(), value, indexed, docValued, stored)); + context.doc().addAll(NumberFieldMapper.NumberType.INTEGER.createFields(name(), value, indexed, docValued, stored)); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java index 43b91fcfca2..834d2c4f766 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; @@ -38,7 +37,6 @@ import org.elasticsearch.index.query.QueryShardException; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; /** @@ -240,7 +238,7 @@ public abstract class AbstractGeometryFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called"); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapper.java index 0dea1ea2541..f3168127219 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapper.java @@ -33,7 +33,6 @@ import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper.DeprecatedParame import java.io.IOException; import java.text.ParseException; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -298,12 +297,9 @@ public abstract class AbstractShapeGeometryFieldMapper extend shape = geometryIndexer.prepareForIndexing(geometry); } - List fields = new ArrayList<>(); - fields.addAll(geometryIndexer.indexShape(context, shape)); - createFieldNamesField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } + List fields = geometryIndexer.indexShape(context, shape); + context.doc().addAll(fields); + createFieldNamesField(context); } catch (Exception e) { if (ignoreMalformed.value() == false) { throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(), diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java index 1fcd4798c08..b992cdcd27c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.settings.Settings; @@ -30,7 +29,6 @@ import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; /** @@ -150,7 +148,7 @@ public class AllFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { // noop mapper return; } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java index ea8d407f731..a268e278f93 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import com.carrotsearch.hppc.ObjectArrayList; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; @@ -46,7 +45,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.time.ZoneId; import java.util.Base64; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseField; @@ -164,7 +162,7 @@ public class BinaryFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (!fieldType().stored() && !fieldType().hasDocValues()) { return; } @@ -180,7 +178,7 @@ public class BinaryFieldMapper extends FieldMapper { return; } if (fieldType().stored()) { - fields.add(new Field(fieldType().name(), value, fieldType())); + context.doc().add(new Field(fieldType().name(), value, fieldType())); } if (fieldType().hasDocValues()) { @@ -195,7 +193,7 @@ public class BinaryFieldMapper extends FieldMapper { // Only add an entry to the field names field if the field is stored // but has no doc values so exists query will work on a field with // no doc values - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java index 3def7265d4c..06d753f4b6e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; @@ -46,7 +45,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.time.ZoneId; import java.util.Iterator; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseField; @@ -229,7 +227,7 @@ public class BooleanFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) { return; } @@ -250,12 +248,12 @@ public class BooleanFieldMapper extends FieldMapper { return; } if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { - fields.add(new Field(fieldType().name(), value ? "T" : "F", fieldType())); + context.doc().add(new Field(fieldType().name(), value ? "T" : "F", fieldType())); } if (fieldType().hasDocValues()) { - fields.add(new SortedNumericDocValuesField(fieldType().name(), value ? 1 : 0)); + context.doc().add(new SortedNumericDocValuesField(fieldType().name(), value ? 1 : 0)); } else { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index a9a9e8fbeeb..5e075fa5cad 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.apache.logging.log4j.LogManager; import org.apache.lucene.codecs.PostingsFormat; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; @@ -52,7 +51,6 @@ import org.elasticsearch.search.suggest.completion.context.ContextMapping; import org.elasticsearch.search.suggest.completion.context.ContextMappings; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -498,12 +496,7 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp } } - List fields = new ArrayList<>(1); - createFieldNamesField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } - + createFieldNamesField(context); for (CompletionInputMetadata metadata: inputMap.values()) { ParseContext externalValueContext = context.createExternalValueContext(metadata); multiFields.parse(this, externalValueContext); @@ -662,7 +655,7 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { // no-op } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index d3a781d2d65..581a108667b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -24,7 +24,6 @@ import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.Term; import org.apache.lucene.search.BoostQuery; @@ -602,7 +601,7 @@ public final class DateFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { String dateAsString; if (context.externalValueSet()) { Object dateAsObject = context.externalValue(); @@ -636,15 +635,15 @@ public final class DateFieldMapper extends FieldMapper { } if (fieldType().indexOptions() != IndexOptions.NONE) { - fields.add(new LongPoint(fieldType().name(), timestamp)); + context.doc().add(new LongPoint(fieldType().name(), timestamp)); } if (fieldType().hasDocValues()) { - fields.add(new SortedNumericDocValuesField(fieldType().name(), timestamp)); + context.doc().add(new SortedNumericDocValuesField(fieldType().name(), timestamp)); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } if (fieldType().stored()) { - fields.add(new StoredField(fieldType().name(), timestamp)); + context.doc().add(new StoredField(fieldType().name(), timestamp)); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index f619be24e4c..f84789eb5f0 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -21,11 +21,9 @@ package org.elasticsearch.index.mapper; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; - import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.Version; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.lucene.Lucene; @@ -45,10 +43,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.HashMap; import java.util.Objects; import java.util.TreeMap; import java.util.stream.StreamSupport; @@ -279,12 +277,8 @@ public abstract class FieldMapper extends Mapper implements Cloneable { * Parse the field value using the provided {@link ParseContext}. */ public void parse(ParseContext context) throws IOException { - final List fields = new ArrayList<>(2); try { - parseCreateField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } + parseCreateField(context); } catch (Exception e) { String valuePreview = ""; try { @@ -309,19 +303,18 @@ public abstract class FieldMapper extends Mapper implements Cloneable { } /** - * Parse the field value and populate fields. + * Parse the field value and populate the fields on {@link ParseContext#doc()}. * * Implementations of this method should ensure that on failing to parse parser.currentToken() must be the * current failing token */ - protected abstract void parseCreateField(ParseContext context, List fields) throws IOException; + protected abstract void parseCreateField(ParseContext context) throws IOException; - protected void createFieldNamesField(ParseContext context, List fields) { - FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context.docMapper() - .metadataMapper(FieldNamesFieldMapper.class).fieldType(); + protected void createFieldNamesField(ParseContext context) { + FieldNamesFieldType fieldNamesFieldType = context.docMapper().metadataMapper(FieldNamesFieldMapper.class).fieldType(); if (fieldNamesFieldType != null && fieldNamesFieldType.isEnabled()) { for (String fieldName : FieldNamesFieldMapper.extractFieldNames(fieldType().name())) { - fields.add(new Field(FieldNamesFieldMapper.NAME, fieldName, fieldNamesFieldType)); + context.doc().add(new Field(FieldNamesFieldMapper.NAME, fieldName, fieldNamesFieldType)); } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java index 9a1b7faf69c..23fe5886a79 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java @@ -259,7 +259,7 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (fieldType().isEnabled() == false) { return; } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 89ebd971519..a26897e9c8d 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -22,7 +22,6 @@ import org.apache.lucene.document.LatLonDocValuesField; import org.apache.lucene.document.LatLonPoint; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; @@ -42,9 +41,7 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseField; @@ -226,11 +223,7 @@ public class GeoPointFieldMapper extends AbstractGeometryFieldMapper implements if (fieldType.hasDocValues()) { context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon())); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { - List fields = new ArrayList<>(1); - createFieldNamesField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } + createFieldNamesField(context); } // if the mapping contains multifields then use the geohash string if (multiFields.iterator().hasNext()) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java index 5cea22dc393..b80cb7c8c57 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import org.apache.logging.log4j.LogManager; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; @@ -35,10 +34,10 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.fielddata.LeafFieldData; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexFieldDataCache; +import org.elasticsearch.index.fielddata.LeafFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; @@ -52,8 +51,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.sort.BucketedSort; import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.util.Arrays; @@ -303,10 +300,10 @@ public class IdFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) { BytesRef id = Uid.encodeId(context.sourceToParse().id()); - fields.add(new Field(NAME, id, fieldType)); + context.doc().add(new Field(NAME, id, fieldType)); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java index 4bbc36362aa..ebdec4036bb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermRangeQuery; import org.elasticsearch.common.lucene.Lucene; @@ -30,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; -import java.util.List; import java.util.Map; /** @@ -134,7 +132,7 @@ public final class IgnoredFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { for (String field : context.getIgnoredFields()) { context.doc().add(new Field(NAME, field, fieldType())); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java index 649535d216a..09ae3160406 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.Lucene; @@ -33,7 +32,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; -import java.util.List; import java.util.Map; @@ -138,7 +136,7 @@ public class IndexFieldMapper extends MetadataFieldMapper { public void preParse(ParseContext context) throws IOException {} @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException {} + protected void parseCreateField(ParseContext context) throws IOException {} @Override protected String contentType() { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java index a3abf963104..25de00a3efb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.InetAddressPoint; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; @@ -352,7 +351,7 @@ public class IpFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { Object addressAsObject; if (context.externalValueSet()) { addressAsObject = context.externalValue(); @@ -386,15 +385,15 @@ public class IpFieldMapper extends FieldMapper { } if (fieldType().indexOptions() != IndexOptions.NONE) { - fields.add(new InetAddressPoint(fieldType().name(), address)); + context.doc().add(new InetAddressPoint(fieldType().name(), address)); } if (fieldType().hasDocValues()) { - fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address)))); + context.doc().add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address)))); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } if (fieldType().stored()) { - fields.add(new StoredField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address)))); + context.doc().add(new StoredField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address)))); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index b83427a53a3..af52e1edace 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -25,7 +25,6 @@ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.NormsFieldExistsQuery; @@ -337,7 +336,7 @@ public final class KeywordFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -379,15 +378,15 @@ public final class KeywordFieldMapper extends FieldMapper { final BytesRef binaryValue = new BytesRef(value); if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), binaryValue, fieldType()); - fields.add(field); + context.doc().add(field); if (fieldType().hasDocValues() == false && fieldType().omitNorms()) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } if (fieldType().hasDocValues()) { - fields.add(new SortedSetDocValuesField(fieldType().name(), binaryValue)); + context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue)); } } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index fa7055cadd2..bd1b93f79fe 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -30,7 +30,6 @@ import org.apache.lucene.document.LongPoint; import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.DocValuesFieldExistsQuery; @@ -1039,8 +1038,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { - + protected void parseCreateField(ParseContext context) throws IOException { XContentParser parser = context.parser(); Object value; Number numericValue = null; @@ -1081,9 +1079,10 @@ public class NumberFieldMapper extends FieldMapper { boolean indexed = fieldType().indexOptions() != IndexOptions.NONE; boolean docValued = fieldType().hasDocValues(); boolean stored = fieldType().stored(); - fields.addAll(fieldType().type.createFields(fieldType().name(), numericValue, indexed, docValued, stored)); + context.doc().addAll(fieldType().type.createFields(fieldType().name(), numericValue, indexed, docValued, stored)); + if (docValued == false && (stored || indexed)) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ParseContext.java b/server/src/main/java/org/elasticsearch/index/mapper/ParseContext.java index e463ed88aa6..5e890d69fef 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ParseContext.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ParseContext.java @@ -89,6 +89,10 @@ public abstract class ParseContext implements Iterable{ return fields; } + public void addAll(List fields) { + this.fields.addAll(fields); + } + public void add(IndexableField field) { // either a meta fields or starts with the prefix assert field.name().startsWith("_") || field.name().startsWith(prefix) : field.name() + " " + prefix; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index 6dee473e9a0..8a9591a68eb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.DocValuesFieldExistsQuery; @@ -56,7 +55,6 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; @@ -344,7 +342,7 @@ public class RangeFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { Range range; if (context.externalValueSet()) { range = context.parseExternalValue(Range.class); @@ -403,9 +401,10 @@ public class RangeFieldMapper extends FieldMapper { boolean indexed = fieldType.indexOptions() != IndexOptions.NONE; boolean docValued = fieldType.hasDocValues(); boolean stored = fieldType.stored(); - fields.addAll(fieldType().rangeType.createFields(context, name(), range, indexed, docValued, stored)); + context.doc().addAll(fieldType().rangeType.createFields(context, name(), range, indexed, docValued, stored)); + if (docValued == false && (indexed || stored)) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java index 17359335ab2..308ed66a77f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; @@ -34,7 +33,6 @@ import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; import java.util.Collections; import java.util.Iterator; -import java.util.List; import java.util.Map; public class RoutingFieldMapper extends MetadataFieldMapper { @@ -166,12 +164,12 @@ public class RoutingFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { String routing = context.sourceToParse().routing(); if (routing != null) { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { - fields.add(new Field(fieldType().name(), routing, fieldType())); - createFieldNamesField(context, fields); + context.doc().add(new Field(fieldType().name(), routing, fieldType())); + createFieldNamesField(context); } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java index 0abcfcda8ac..b7c9d229510 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.LongPoint; import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.index.DocValuesType; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; @@ -237,14 +236,14 @@ public class SeqNoFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { // see InternalEngine.innerIndex to see where the real version value is set // also see ParsedDocument.updateSeqID (called by innerIndex) SequenceIDFields seqID = SequenceIDFields.emptySeqID(); context.seqID(seqID); - fields.add(seqID.seqNo); - fields.add(seqID.seqNoDocValue); - fields.add(seqID.primaryTerm); + context.doc().add(seqID.seqNo); + context.doc().add(seqID.seqNoDocValue); + context.doc().add(seqID.primaryTerm); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java index 4f5e1b79bd1..2ac2d515276 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Nullable; @@ -226,21 +225,21 @@ public class SourceFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { BytesReference originalSource = context.sourceToParse().source(); XContentType contentType = context.sourceToParse().getXContentType(); final BytesReference adaptedSource = applyFilters(originalSource, contentType); if (adaptedSource != null) { final BytesRef ref = adaptedSource.toBytesRef(); - fields.add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length)); + context.doc().add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length)); } if (originalSource != null && adaptedSource != originalSource && context.indexSettings().isSoftDeleteEnabled()) { // if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery BytesRef ref = originalSource.toBytesRef(); - fields.add(new StoredField(RECOVERY_SOURCE_NAME, ref.bytes, ref.offset, ref.length)); - fields.add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1)); + context.doc().add(new StoredField(RECOVERY_SOURCE_NAME, ref.bytes, ref.offset, ref.length)); + context.doc().add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1)); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index 8b9df6db76a..1bc6bee97c7 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -31,7 +31,6 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.queries.intervals.Intervals; import org.apache.lucene.queries.intervals.IntervalsSource; @@ -484,7 +483,7 @@ public class TextFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException(); } @@ -500,12 +499,12 @@ public class TextFieldMapper extends FieldMapper { super(fieldType.name(), fieldType, fieldType, indexSettings, MultiFields.empty(), CopyTo.empty()); } - void addField(String value, List fields) { - fields.add(new Field(fieldType().name(), value, fieldType())); + void addField(ParseContext context, String value) { + context.doc().add(new Field(fieldType().name(), value, fieldType())); } @Override - protected void parseCreateField(ParseContext context, List fields) { + protected void parseCreateField(ParseContext context) { throw new UnsupportedOperationException(); } @@ -822,7 +821,7 @@ public class TextFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -836,15 +835,15 @@ public class TextFieldMapper extends FieldMapper { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), value, fieldType()); - fields.add(field); + context.doc().add(field); if (fieldType().omitNorms()) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } if (prefixFieldMapper != null) { - prefixFieldMapper.addField(value, fields); + prefixFieldMapper.addField(context, value); } if (phraseFieldMapper != null) { - fields.add(new Field(phraseFieldMapper.fieldType.name(), value, phraseFieldMapper.fieldType)); + context.doc().add(new Field(phraseFieldMapper.fieldType.name(), value, phraseFieldMapper.fieldType)); } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 34d31d6f717..6ae4ae52e86 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermStates; import org.apache.lucene.search.BooleanClause; @@ -313,13 +312,13 @@ public class TypeFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) { return; } - fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); + context.doc().add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); if (fieldType().hasDocValues()) { - fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type()))); + context.doc().add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(MapperService.SINGLE_MAPPING_NAME))); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java index 9742e084f7e..962f5096452 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.settings.Settings; @@ -33,7 +32,6 @@ import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardException; import java.io.IOException; -import java.util.List; import java.util.Map; /** Mapper for the _version field. */ @@ -110,11 +108,11 @@ public class VersionFieldMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { // see InternalEngine.updateVersion to see where the real version value is set final Field version = new NumericDocValuesField(NAME, -1L); context.version(version); - fields.add(version); + context.doc().add(version); } @Override diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentFieldMapperTests.java index 959150caf20..dec1f7214c2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentFieldMapperTests.java @@ -23,7 +23,6 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; @@ -40,7 +39,6 @@ import java.io.IOException; import java.io.StringReader; import java.util.Arrays; import java.util.Collections; -import java.util.List; public class DocumentFieldMapperTests extends LuceneTestCase { @@ -113,7 +111,7 @@ public class DocumentFieldMapperTests extends LuceneTestCase { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { } @Override diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java index e9ddd9646e5..3e7de5b0c88 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java @@ -19,15 +19,14 @@ package org.elasticsearch.index.mapper; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.elasticsearch.Version; -import org.elasticsearch.common.geo.builders.PointBuilder; import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.geo.builders.PointBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.geometry.Point; @@ -37,7 +36,6 @@ import java.io.IOException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Iterator; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseField; @@ -202,7 +200,7 @@ public class ExternalMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException(); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMetadataMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMetadataMapper.java index e8c38bc1a5a..dcb9eede6e9 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMetadataMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMetadataMapper.java @@ -21,14 +21,12 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.StringField; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.util.Collections; import java.util.Iterator; -import java.util.List; import java.util.Map; public class ExternalMetadataMapper extends MetadataFieldMapper { @@ -48,7 +46,7 @@ public class ExternalMetadataMapper extends MetadataFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { // handled in post parse } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java index 8d8a2f98866..bc97b1a68dd 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; @@ -33,7 +32,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseTextField; @@ -121,7 +119,7 @@ public class FakeStringFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -135,10 +133,10 @@ public class FakeStringFieldMapper extends FieldMapper { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), value, fieldType()); - fields.add(field); + context.doc().add(field); } if (fieldType().hasDocValues()) { - fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(value))); + context.doc().add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(value))); } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/MockFieldMapper.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/MockFieldMapper.java index b51102c387d..c64a26b2aa0 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/MockFieldMapper.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/MockFieldMapper.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryShardContext; import java.io.IOException; -import java.util.List; // this sucks how much must be overridden just do get a dummy field mapper... public class MockFieldMapper extends FieldMapper { @@ -88,6 +87,6 @@ public class MockFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List list) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { } } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java index ceab5dc8dfb..cc64098cff6 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java @@ -13,7 +13,6 @@ import org.apache.lucene.document.Field; import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; @@ -30,13 +29,13 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentSubParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.index.fielddata.LeafHistogramFieldData; import org.elasticsearch.index.fielddata.HistogramValue; import org.elasticsearch.index.fielddata.HistogramValues; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexHistogramFieldData; +import org.elasticsearch.index.fielddata.LeafHistogramFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.mapper.FieldMapper; @@ -58,7 +57,6 @@ import org.elasticsearch.xpack.analytics.aggregations.support.AnalyticsValuesSou import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; @@ -169,7 +167,7 @@ public class HistogramFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called"); } diff --git a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java index cf35ae9c90a..0551d7ba848 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java +++ b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java @@ -7,14 +7,7 @@ package org.elasticsearch.xpack.constantkeyword.mapper; -import java.io.IOException; -import java.time.ZoneId; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.MultiTermQuery; @@ -46,6 +39,12 @@ import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import java.io.IOException; +import java.time.ZoneId; +import java.util.List; +import java.util.Map; +import java.util.Objects; + /** * A {@link FieldMapper} that assigns every document the same value. */ @@ -277,7 +276,7 @@ public class ConstantKeywordFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { String value; if (context.externalValueSet()) { value = context.externalValue().toString(); diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java index 5d5ed7bd48e..9f0cdb6900c 100644 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java +++ b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java @@ -9,7 +9,6 @@ package org.elasticsearch.xpack.flattened.mapper; import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.OrdinalMap; import org.apache.lucene.index.Term; @@ -31,11 +30,11 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.NamedAnalyzer; -import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData; import org.elasticsearch.index.fielddata.IndexFieldData; +import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData; -import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; +import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData; import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; @@ -60,7 +59,6 @@ import org.elasticsearch.search.sort.SortOrder; import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -603,7 +601,7 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { if (context.parser().currentToken() == XContentParser.Token.VALUE_NULL) { return; } @@ -614,10 +612,10 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper { } XContentParser xContentParser = context.parser(); - fields.addAll(fieldParser.parse(xContentParser)); + context.doc().addAll(fieldParser.parse(xContentParser)); if (!fieldType.hasDocValues()) { - createFieldNamesField(context, fields); + createFieldNamesField(context); } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java index 9ea3c68f407..7c1c4ddd34c 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java @@ -9,7 +9,6 @@ import org.apache.lucene.document.StoredField; import org.apache.lucene.document.XYDocValuesField; import org.apache.lucene.document.XYPointField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.ParseField; @@ -27,9 +26,7 @@ import org.elasticsearch.xpack.spatial.common.CartesianPoint; import org.elasticsearch.xpack.spatial.index.query.ShapeQueryPointProcessor; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import java.util.Map; import static org.elasticsearch.index.mapper.TypeParsers.parseField; @@ -174,11 +171,7 @@ public class PointFieldMapper extends AbstractGeometryFieldMapper implements Arr if (fieldType.hasDocValues()) { context.doc().add(new XYDocValuesField(fieldType().name(), point.getX(), point.getY())); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { - List fields = new ArrayList<>(1); - createFieldNamesField(context, fields); - for (IndexableField field : fields) { - context.doc().add(field); - } + createFieldNamesField(context); } // if the mapping contains multi-fields then throw an error? if (multiFields.iterator().hasNext()) { diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java index a3e7b23b871..2f42a951a19 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java @@ -9,7 +9,6 @@ package org.elasticsearch.xpack.vectors.mapper; import org.apache.lucene.document.BinaryDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; @@ -34,7 +33,6 @@ import org.elasticsearch.xpack.vectors.query.VectorDVIndexFieldData; import java.io.IOException; import java.nio.ByteBuffer; import java.time.ZoneId; -import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; @@ -232,7 +230,7 @@ public class DenseVectorFieldMapper extends FieldMapper implements ArrayValueMap } @Override - protected void parseCreateField(ParseContext context, List fields) { + protected void parseCreateField(ParseContext context) { throw new AssertionError("parse is implemented directly"); } diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java index 0b4abff4bb3..aa77bde6365 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java @@ -10,7 +10,6 @@ package org.elasticsearch.xpack.vectors.mapper; import org.apache.logging.log4j.LogManager; import org.apache.lucene.document.BinaryDocValuesField; import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.ArrayUtil; @@ -30,7 +29,6 @@ import org.elasticsearch.xpack.vectors.query.VectorDVIndexFieldData; import java.io.IOException; import java.time.ZoneId; -import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; @@ -194,7 +192,7 @@ public class SparseVectorFieldMapper extends FieldMapper { @Override - protected void parseCreateField(ParseContext context, List fields) { + protected void parseCreateField(ParseContext context) { throw new AssertionError("parse is implemented directly"); } diff --git a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java index a5d3f8a7815..da0d781e4ff 100644 --- a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java +++ b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java @@ -532,7 +532,7 @@ public class WildcardFieldMapper extends FieldMapper { } @Override - protected void parseCreateField(ParseContext context, List fields) throws IOException { + protected void parseCreateField(ParseContext context) throws IOException { final String value; if (context.externalValueSet()) { value = context.externalValue().toString(); @@ -546,7 +546,9 @@ public class WildcardFieldMapper extends FieldMapper { } ParseContext.Document parseDoc = context.doc(); + List fields = new ArrayList<>(); createFields(value, parseDoc, fields); + parseDoc.addAll(fields); } // For internal use by Lucene only - used to define ngram index