Simplify signature of FieldMapper#parseCreateField. (#56144)

`FieldMapper#parseCreateField` accepts the parse context, plus a list of fields
as an output parameter. These fields are immediately added to the document
through `ParseContext#doc()`.

This commit simplifies the signature by removing the list of fields, and having
the mappers add the fields directly to `ParseContext#doc()`. I think this is
nicer for implementors, because previously fields could be added either through
the list, or the context (through `add`, `addWithKey`, etc.)
This commit is contained in:
Julie Tibshirani 2020-05-06 11:12:09 -07:00 committed by GitHub
parent e6dce13bda
commit e852bb29b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 147 additions and 242 deletions

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
float value;
if (context.externalValueSet()) {
Object v = context.externalValue();

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new AssertionError("Should never be called");
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new AssertionError("parse is implemented directly");
}

View File

@ -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<IndexableField> 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<Field> 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);
}
}

View File

@ -484,7 +484,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
}
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> 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<IndexableField> 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<IndexableField> 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<IndexableField> 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

View File

@ -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<IndexableField> 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));
}
/**

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new IllegalStateException("Should never be called");
}

View File

@ -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<IndexableField> 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));
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new UnsupportedOperationException("parsing is implemented in parse(), this method should NEVER be called");
}

View File

@ -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<IndexableField> 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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new UnsupportedOperationException("should not be invoked");
}

View File

@ -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<IndexableField> 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);
}
}
}

View File

@ -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<IndexableField> 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);
}
}
}

View File

@ -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<IndexableField> 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));
}
}
}

View File

@ -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<IndexableField> 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

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called");
}

View File

@ -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<Parsed, Processed> extend
shape = geometryIndexer.prepareForIndexing(geometry);
}
List<IndexableField> fields = new ArrayList<>();
fields.addAll(geometryIndexer.indexShape(context, shape));
createFieldNamesField(context, fields);
for (IndexableField field : fields) {
context.doc().add(field);
}
List<IndexableField> 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(),

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
// noop mapper
return;
}

View File

@ -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<IndexableField> 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);
}
}

View File

@ -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<IndexableField> 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);
}
}

View File

@ -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<IndexableField> 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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
// no-op
}

View File

@ -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<IndexableField> 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));
}
}

View File

@ -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<IndexableField> 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 <code>fields</code>.
* 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<IndexableField> fields) throws IOException;
protected abstract void parseCreateField(ParseContext context) throws IOException;
protected void createFieldNamesField(ParseContext context, List<IndexableField> 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));
}
}
}

View File

@ -259,7 +259,7 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper {
}
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
if (fieldType().isEnabled() == false) {
return;
}

View File

@ -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<IndexableField> 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()) {

View File

@ -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<IndexableField> 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));
}
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
for (String field : context.getIgnoredFields()) {
context.doc().add(new Field(NAME, field, fieldType()));
}

View File

@ -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<IndexableField> fields) throws IOException {}
protected void parseCreateField(ParseContext context) throws IOException {}
@Override
protected String contentType() {

View File

@ -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<IndexableField> 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))));
}
}

View File

@ -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<IndexableField> 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

View File

@ -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<IndexableField> 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);
}
}

View File

@ -89,6 +89,10 @@ public abstract class ParseContext implements Iterable<ParseContext.Document>{
return fields;
}
public void addAll(List<? extends IndexableField> 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;

View File

@ -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<IndexableField> 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);
}
}

View File

@ -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<IndexableField> 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);
}
}
}

View File

@ -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<IndexableField> 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

View File

@ -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<IndexableField> 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));
}
}

View File

@ -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<IndexableField> 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<IndexableField> 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<IndexableField> 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<IndexableField> 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));
}
}
}

View File

@ -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<IndexableField> 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)));
}
}

View File

@ -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<IndexableField> 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

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
}
@Override

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new UnsupportedOperationException();
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
// handled in post parse
}

View File

@ -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<IndexableField> 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)));
}
}

View File

@ -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 {
}
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called");
}

View File

@ -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<IndexableField> fields) throws IOException {
protected void parseCreateField(ParseContext context) throws IOException {
String value;
if (context.externalValueSet()) {
value = context.externalValue().toString();

View File

@ -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<IndexableField> 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);
}
}

View File

@ -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<IndexableField> 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()) {

View File

@ -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<IndexableField> fields) {
protected void parseCreateField(ParseContext context) {
throw new AssertionError("parse is implemented directly");
}

View File

@ -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<IndexableField> fields) {
protected void parseCreateField(ParseContext context) {
throw new AssertionError("parse is implemented directly");
}

View File

@ -532,7 +532,7 @@ public class WildcardFieldMapper extends FieldMapper {
}
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> 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<IndexableField> fields = new ArrayList<>();
createFields(value, parseDoc, fields);
parseDoc.addAll(fields);
}
// For internal use by Lucene only - used to define ngram index