Rename Mapper#name to Mapper#leafName (#109971)

This addresses a long standing TODO that caused quite a few bugs over time, in that the mapper name does not include its full path, while
the MappedFieldType name does.
This commit is contained in:
Luca Cavanna 2024-06-21 11:48:17 +02:00 committed by GitHub
parent d79f18d069
commit 15c7abe111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 179 additions and 150 deletions

View file

@ -323,7 +323,7 @@ public class LegacyGeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<
private GeoShapeFieldType buildFieldType(LegacyGeoShapeParser parser, MapperBuilderContext context) {
GeoShapeFieldType ft = new GeoShapeFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
orientation.get().value(),
parser,
@ -352,7 +352,7 @@ public class LegacyGeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<
public LegacyGeoShapeFieldMapper build(MapperBuilderContext context) {
LegacyGeoShapeParser parser = new LegacyGeoShapeParser();
GeoShapeFieldType ft = buildFieldType(parser, context);
return new LegacyGeoShapeFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
return new LegacyGeoShapeFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
}
}

View file

@ -127,7 +127,7 @@ public class MatchOnlyTextFieldMapper extends FieldMapper {
NamedAnalyzer indexAnalyzer = analyzers.getIndexAnalyzer();
TextSearchInfo tsi = new TextSearchInfo(Defaults.FIELD_TYPE, null, searchAnalyzer, searchQuoteAnalyzer);
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
tsi,
indexAnalyzer,
context.isSourceSynthetic(),
@ -140,7 +140,15 @@ public class MatchOnlyTextFieldMapper extends FieldMapper {
public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
MatchOnlyTextFieldType tft = buildFieldType(context);
MultiFields multiFields = multiFieldsBuilder.build(this, context);
return new MatchOnlyTextFieldMapper(name(), Defaults.FIELD_TYPE, tft, multiFields, copyTo, context.isSourceSynthetic(), this);
return new MatchOnlyTextFieldMapper(
leafName(),
Defaults.FIELD_TYPE,
tft,
multiFields,
copyTo,
context.isSourceSynthetic(),
this
);
}
}

View file

@ -91,9 +91,9 @@ public class RankFeatureFieldMapper extends FieldMapper {
@Override
public RankFeatureFieldMapper build(MapperBuilderContext context) {
return new RankFeatureFieldMapper(
name(),
leafName(),
new RankFeatureFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
meta.getValue(),
positiveScoreImpact.getValue(),
nullValue.getValue()

View file

@ -64,8 +64,8 @@ public class RankFeaturesFieldMapper extends FieldMapper {
@Override
public RankFeaturesFieldMapper build(MapperBuilderContext context) {
return new RankFeaturesFieldMapper(
name(),
new RankFeaturesFieldType(context.buildFullName(name()), meta.getValue(), positiveScoreImpact.getValue()),
leafName(),
new RankFeaturesFieldType(context.buildFullName(leafName()), meta.getValue(), positiveScoreImpact.getValue()),
multiFieldsBuilder.build(this, context),
copyTo,
positiveScoreImpact.getValue()

View file

@ -187,7 +187,7 @@ public class ScaledFloatFieldMapper extends FieldMapper {
@Override
public ScaledFloatFieldMapper build(MapperBuilderContext context) {
ScaledFloatFieldType type = new ScaledFloatFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.getValue(),
stored.getValue(),
hasDocValues.getValue(),
@ -198,7 +198,7 @@ public class ScaledFloatFieldMapper extends FieldMapper {
indexMode
);
return new ScaledFloatFieldMapper(
name(),
leafName(),
type,
multiFieldsBuilder.build(this, context),
copyTo,

View file

@ -187,7 +187,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
NamedAnalyzer searchAnalyzer = analyzers.getSearchAnalyzer();
SearchAsYouTypeFieldType ft = new SearchAsYouTypeFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
fieldType,
similarity.getValue(),
analyzers.getSearchAnalyzer(),
@ -202,7 +202,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
prefixft.setIndexOptions(fieldType.indexOptions());
prefixft.setOmitNorms(true);
prefixft.setStored(false);
final String fullName = context.buildFullName(name());
final String fullName = context.buildFullName(leafName());
// wrap the root field's index analyzer with shingles and edge ngrams
final Analyzer prefixIndexWrapper = SearchAsYouTypeAnalyzer.withShingleAndPrefix(
indexAnalyzer.analyzer(),
@ -228,7 +228,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
final int shingleSize = i + 2;
FieldType shingleft = new FieldType(fieldType);
shingleft.setStored(false);
String fieldName = getShingleFieldName(context.buildFullName(name()), shingleSize);
String fieldName = getShingleFieldName(context.buildFullName(leafName()), shingleSize);
// wrap the root field's index, search, and search quote analyzers with shingles
final SearchAsYouTypeAnalyzer shingleIndexWrapper = SearchAsYouTypeAnalyzer.withShingle(
indexAnalyzer.analyzer(),
@ -260,7 +260,7 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
ft.setPrefixField(prefixFieldType);
ft.setShingleFields(shingleFieldTypes);
return new SearchAsYouTypeFieldMapper(
name(),
leafName(),
ft,
copyTo,
indexAnalyzers,

View file

@ -77,17 +77,17 @@ public class TokenCountFieldMapper extends FieldMapper {
@Override
public TokenCountFieldMapper build(MapperBuilderContext context) {
if (analyzer.getValue() == null) {
throw new MapperParsingException("Analyzer must be set for field [" + name() + "] but wasn't.");
throw new MapperParsingException("Analyzer must be set for field [" + leafName() + "] but wasn't.");
}
MappedFieldType ft = new TokenCountFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
index.getValue(),
store.getValue(),
hasDocValues.getValue(),
nullValue.getValue(),
meta.getValue()
);
return new TokenCountFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
return new TokenCountFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
}
}

View file

@ -123,16 +123,16 @@ public final class ParentJoinFieldMapper extends FieldMapper {
"Adding multifields to [" + CONTENT_TYPE + "] mappers has no effect and will be forbidden in future"
);
}
checkObjectOrNested(context, name());
checkObjectOrNested(context, leafName());
final Map<String, ParentIdFieldMapper> parentIdFields = new HashMap<>();
relations.get()
.stream()
.map(relation -> new ParentIdFieldMapper(name() + "#" + relation.parent(), eagerGlobalOrdinals.get()))
.map(relation -> new ParentIdFieldMapper(leafName() + "#" + relation.parent(), eagerGlobalOrdinals.get()))
.forEach(mapper -> parentIdFields.put(mapper.name(), mapper));
Joiner joiner = new Joiner(name(), relations.get());
Joiner joiner = new Joiner(leafName(), relations.get());
return new ParentJoinFieldMapper(
name(),
new JoinFieldType(context.buildFullName(name()), joiner, meta.get()),
leafName(),
new JoinFieldType(context.buildFullName(leafName()), joiner, meta.get()),
Collections.unmodifiableMap(parentIdFields),
eagerGlobalOrdinals.get(),
relations.get()

View file

@ -135,10 +135,10 @@ public class PercolatorFieldMapper extends FieldMapper {
@Override
public PercolatorFieldMapper build(MapperBuilderContext context) {
PercolatorFieldType fieldType = new PercolatorFieldType(context.buildFullName(name()), meta.getValue());
PercolatorFieldType fieldType = new PercolatorFieldType(context.buildFullName(leafName()), meta.getValue());
// TODO should percolator even allow multifields?
MultiFields multiFields = multiFieldsBuilder.build(this, context);
context = context.createChildContext(name(), null);
context = context.createChildContext(leafName(), null);
KeywordFieldMapper extractedTermsField = createExtractQueryFieldBuilder(
EXTRACTED_TERMS_FIELD_NAME,
context,
@ -162,7 +162,7 @@ public class PercolatorFieldMapper extends FieldMapper {
fieldType.mapUnmappedFieldsAsText = mapUnmappedFieldsAsText;
return new PercolatorFieldMapper(
name(),
leafName(),
fieldType,
multiFields,
copyTo,

View file

@ -327,7 +327,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper {
final CollatorParams params = collatorParams();
final Collator collator = params.buildCollator();
CollationFieldType ft = new CollationFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.getValue(),
stored.getValue(),
hasDocValues.getValue(),
@ -337,7 +337,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper {
meta.getValue()
);
return new ICUCollationKeywordFieldMapper(
name(),
leafName(),
buildFieldType(),
ft,
multiFieldsBuilder.build(this, context),

View file

@ -139,7 +139,7 @@ public class AnnotatedTextFieldMapper extends FieldMapper {
wrapAnalyzer(analyzers.getSearchQuoteAnalyzer())
);
return new AnnotatedTextFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
store.getValue(),
tsi,
context.isSourceSynthetic(),
@ -158,12 +158,12 @@ public class AnnotatedTextFieldMapper extends FieldMapper {
if (analyzers.positionIncrementGap.isConfigured()) {
if (fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
throw new IllegalArgumentException(
"Cannot set position_increment_gap on field [" + name() + "] without positions enabled"
"Cannot set position_increment_gap on field [" + leafName() + "] without positions enabled"
);
}
}
return new AnnotatedTextFieldMapper(
name(),
leafName(),
fieldType,
buildFieldType(fieldType, context, multiFields),
multiFields,

View file

@ -55,8 +55,8 @@ public class Murmur3FieldMapper extends FieldMapper {
@Override
public Murmur3FieldMapper build(MapperBuilderContext context) {
return new Murmur3FieldMapper(
name(),
new Murmur3FieldType(context.buildFullName(name()), stored.getValue(), meta.getValue()),
leafName(),
new Murmur3FieldType(context.buildFullName(leafName()), stored.getValue(), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo
);

View file

@ -70,8 +70,8 @@ public class BinaryFieldMapper extends FieldMapper {
@Override
public BinaryFieldMapper build(MapperBuilderContext context) {
return new BinaryFieldMapper(
name(),
new BinaryFieldType(context.buildFullName(name()), stored.getValue(), hasDocValues.getValue(), meta.getValue()),
leafName(),
new BinaryFieldType(context.buildFullName(leafName()), stored.getValue(), hasDocValues.getValue(), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo,
this

View file

@ -116,7 +116,7 @@ public class BooleanFieldMapper extends FieldMapper {
@Override
public BooleanFieldMapper build(MapperBuilderContext context) {
MappedFieldType ft = new BooleanFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.getValue(),
docValues.getValue(),
@ -124,7 +124,14 @@ public class BooleanFieldMapper extends FieldMapper {
scriptValues(),
meta.getValue()
);
return new BooleanFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, context.isSourceSynthetic(), this);
return new BooleanFieldMapper(
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,
context.isSourceSynthetic(),
this
);
}
private FieldValues<Boolean> scriptValues() {
@ -134,7 +141,7 @@ public class BooleanFieldMapper extends FieldMapper {
BooleanFieldScript.Factory scriptFactory = scriptCompiler.compile(script.get(), BooleanFieldScript.CONTEXT);
return scriptFactory == null
? null
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(leafName(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}

View file

@ -205,9 +205,9 @@ public class CompletionFieldMapper extends FieldMapper {
new CompletionAnalyzer(this.searchAnalyzer.getValue(), preserveSeparators.getValue(), preservePosInc.getValue())
);
CompletionFieldType ft = new CompletionFieldType(context.buildFullName(name()), completionAnalyzer, meta.getValue());
CompletionFieldType ft = new CompletionFieldType(context.buildFullName(leafName()), completionAnalyzer, meta.getValue());
ft.setContextMappings(contexts.getValue());
return new CompletionFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
return new CompletionFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
}
private void checkCompletionContextsLimit() {
@ -224,7 +224,7 @@ public class CompletionFieldMapper extends FieldMapper {
+ COMPLETION_CONTEXTS_LIMIT
+ "] completion contexts"
+ " in the mapping for field ["
+ name()
+ leafName()
+ "]. "
+ "The maximum allowed number of completion contexts in a mapping will be limited to "
+ "["

View file

@ -293,7 +293,7 @@ public final class DateFieldMapper extends FieldMapper {
logger.warn(() -> "Error parsing format [" + format.getValue() + "] of legacy index, falling back to default", e);
return DateFormatter.forPattern(format.getDefaultValue()).withLocale(locale.getValue());
} else {
throw new IllegalArgumentException("Error parsing [format] on field [" + name() + "]: " + e.getMessage(), e);
throw new IllegalArgumentException("Error parsing [format] on field [" + leafName() + "]: " + e.getMessage(), e);
}
}
}
@ -306,7 +306,7 @@ public final class DateFieldMapper extends FieldMapper {
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(
name(),
leafName(),
script.get().getParams(),
lookup,
buildFormatter(),
@ -327,7 +327,7 @@ public final class DateFieldMapper extends FieldMapper {
return fieldType.parse(nullValue.getValue());
} catch (Exception e) {
if (indexCreatedVersion.onOrAfter(IndexVersions.V_8_0_0)) {
throw new MapperParsingException("Error parsing [null_value] on field [" + name() + "]: " + e.getMessage(), e);
throw new MapperParsingException("Error parsing [null_value] on field [" + leafName() + "]: " + e.getMessage(), e);
} else {
DEPRECATION_LOGGER.warn(
DeprecationCategory.MAPPINGS,
@ -335,7 +335,7 @@ public final class DateFieldMapper extends FieldMapper {
"Error parsing ["
+ nullValue.getValue()
+ "] as date in [null_value] on field ["
+ name()
+ leafName()
+ "]); [null_value] will be ignored"
);
return null;
@ -346,7 +346,7 @@ public final class DateFieldMapper extends FieldMapper {
@Override
public DateFieldMapper build(MapperBuilderContext context) {
DateFieldType ft = new DateFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
index.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
index.getValue(),
store.getValue(),
@ -359,13 +359,13 @@ public final class DateFieldMapper extends FieldMapper {
);
Long nullTimestamp = parseNullValue(ft);
if (name().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
if (leafName().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
&& context.isDataStream()
&& ignoreMalformed.isConfigured() == false) {
ignoreMalformed.setValue(false);
}
return new DateFieldMapper(
name(),
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,

View file

@ -151,8 +151,8 @@ public final class FieldAliasMapper extends Mapper {
@Override
public FieldAliasMapper build(MapperBuilderContext context) {
String fullName = context.buildFullName(name());
return new FieldAliasMapper(name(), fullName, path);
String fullName = context.buildFullName(leafName());
return new FieldAliasMapper(leafName(), fullName, path);
}
}

View file

@ -514,7 +514,7 @@ public abstract class FieldMapper extends Mapper {
private boolean hasSyntheticSourceCompatibleKeywordField;
public Builder add(FieldMapper.Builder builder) {
mapperBuilders.put(builder.name(), builder::build);
mapperBuilders.put(builder.leafName(), builder::build);
if (builder instanceof KeywordFieldMapper.Builder kwd) {
if (kwd.hasNormalizer() == false && (kwd.hasDocValues() || kwd.isStored())) {
@ -559,7 +559,7 @@ public abstract class FieldMapper extends Mapper {
return empty();
} else {
FieldMapper[] mappers = new FieldMapper[mapperBuilders.size()];
context = context.createChildContext(mainFieldBuilder.name(), null);
context = context.createChildContext(mainFieldBuilder.leafName(), null);
int i = 0;
for (Map.Entry<String, Function<MapperBuilderContext, FieldMapper>> entry : this.mapperBuilders.entrySet()) {
mappers[i++] = entry.getValue().apply(context);

View file

@ -188,7 +188,7 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<GeoPoi
GeoPointFieldScript.Factory factory = scriptCompiler.compile(this.script.get(), GeoPointFieldScript.CONTEXT);
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> factory.newFactory(leafName(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
@ -197,7 +197,7 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<GeoPoi
public FieldMapper build(MapperBuilderContext context) {
boolean ignoreMalformedEnabled = ignoreMalformed.get().value();
Parser<GeoPoint> geoParser = new GeoPointParser(
name(),
leafName(),
(parser) -> GeoUtils.parseGeoPoint(parser, ignoreZValue.get().value()),
nullValue.get(),
ignoreZValue.get().value(),
@ -206,7 +206,7 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<GeoPoi
context.isSourceSynthetic() && ignoreMalformedEnabled
);
GeoPointFieldType ft = new GeoPointFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.get(),
hasDocValues.get(),
@ -218,9 +218,9 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<GeoPoi
indexMode
);
if (this.script.get() == null) {
return new GeoPointFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, geoParser, this);
return new GeoPointFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, geoParser, this);
}
return new GeoPointFieldMapper(name(), ft, geoParser, this);
return new GeoPointFieldMapper(leafName(), ft, geoParser, this);
}
}

View file

@ -99,18 +99,18 @@ public class GeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<Geomet
);
GeoShapeParser geoShapeParser = new GeoShapeParser(geometryParser, orientation.get().value());
GeoShapeFieldType ft = new GeoShapeFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
orientation.get().value(),
geoShapeParser,
meta.get()
);
return new GeoShapeFieldMapper(
name(),
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,
new GeoShapeIndexer(orientation.get().value(), context.buildFullName(name())),
new GeoShapeIndexer(orientation.get().value(), context.buildFullName(leafName())),
geoShapeParser,
this
);

View file

@ -131,7 +131,7 @@ public class IpFieldMapper extends FieldMapper {
return InetAddresses.forString(nullValueAsString);
} catch (Exception e) {
if (indexCreatedVersion.onOrAfter(IndexVersions.V_8_0_0)) {
throw new MapperParsingException("Error parsing [null_value] on field [" + name() + "]: " + e.getMessage(), e);
throw new MapperParsingException("Error parsing [null_value] on field [" + leafName() + "]: " + e.getMessage(), e);
} else {
DEPRECATION_LOGGER.warn(
DeprecationCategory.MAPPINGS,
@ -139,7 +139,7 @@ public class IpFieldMapper extends FieldMapper {
"Error parsing ["
+ nullValue.getValue()
+ "] as IP in [null_value] on field ["
+ name()
+ leafName()
+ "]); [null_value] will be ignored"
);
return null;
@ -154,7 +154,7 @@ public class IpFieldMapper extends FieldMapper {
IpFieldScript.Factory factory = scriptCompiler.compile(this.script.get(), IpFieldScript.CONTEXT);
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> factory.newFactory(leafName(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
@ -170,9 +170,9 @@ public class IpFieldMapper extends FieldMapper {
dimension.setValue(true);
}
return new IpFieldMapper(
name(),
leafName(),
new IpFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.getValue(),
hasDocValues.getValue(),

View file

@ -271,7 +271,7 @@ public final class KeywordFieldMapper extends FieldMapper {
StringFieldScript.Factory scriptFactory = scriptCompiler.compile(script.get(), StringFieldScript.CONTEXT);
return scriptFactory == null
? null
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(leafName(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
@ -311,7 +311,7 @@ public final class KeywordFieldMapper extends FieldMapper {
);
normalizer = Lucene.KEYWORD_ANALYZER;
} else {
throw new MapperParsingException("normalizer [" + normalizerName + "] not found for field [" + name() + "]");
throw new MapperParsingException("normalizer [" + normalizerName + "] not found for field [" + leafName() + "]");
}
}
searchAnalyzer = quoteAnalyzer = normalizer;
@ -325,7 +325,7 @@ public final class KeywordFieldMapper extends FieldMapper {
dimension(true);
}
return new KeywordFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
fieldType,
normalizer,
searchAnalyzer,
@ -347,7 +347,7 @@ public final class KeywordFieldMapper extends FieldMapper {
fieldtype = Defaults.FIELD_TYPE;
}
return new KeywordFieldMapper(
name(),
leafName(),
fieldtype,
buildFieldType(context, fieldtype),
multiFieldsBuilder.build(this, context),

View file

@ -24,22 +24,21 @@ public abstract class Mapper implements ToXContentFragment, Iterable<Mapper> {
public abstract static class Builder {
private String name;
private String leafName;
protected Builder(String name) {
setName(name);
protected Builder(String leafName) {
setLeafName(leafName);
}
// TODO rename this to leafName?
public final String name() {
return this.name;
public final String leafName() {
return this.leafName;
}
/** Returns a newly built mapper. */
public abstract Mapper build(MapperBuilderContext context);
void setName(String name) {
this.name = internFieldName(name);
void setLeafName(String leafName) {
this.leafName = internFieldName(leafName);
}
}

View file

@ -82,7 +82,7 @@ public class NestedObjectMapper extends ObjectMapper {
}
parentTypeFilter = Queries.newNonNestedFilter(indexCreatedVersion);
}
final String fullPath = context.buildFullName(name());
final String fullPath = context.buildFullName(leafName());
final String nestedTypePath;
if (indexCreatedVersion.before(IndexVersions.V_8_0_0)) {
nestedTypePath = "__" + fullPath;
@ -91,14 +91,14 @@ public class NestedObjectMapper extends ObjectMapper {
}
final Query nestedTypeFilter = NestedPathFieldMapper.filter(indexCreatedVersion, nestedTypePath);
NestedMapperBuilderContext nestedContext = new NestedMapperBuilderContext(
context.buildFullName(name()),
context.buildFullName(leafName()),
nestedTypeFilter,
parentIncludedInRoot,
context.getDynamic(dynamic),
context.getMergeReason()
);
return new NestedObjectMapper(
name(),
leafName(),
fullPath,
buildMappers(nestedContext),
enabled,

View file

@ -221,7 +221,7 @@ public class NumberFieldMapper extends FieldMapper {
if (this.script.get() == null) {
return null;
}
return type.compile(name(), script.get(), scriptCompiler);
return type.compile(leafName(), script.get(), scriptCompiler);
}
public Builder dimension(boolean dimension) {
@ -265,8 +265,15 @@ public class NumberFieldMapper extends FieldMapper {
dimension.setValue(true);
}
MappedFieldType ft = new NumberFieldType(context.buildFullName(name()), this);
return new NumberFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, context.isSourceSynthetic(), this);
MappedFieldType ft = new NumberFieldType(context.buildFullName(leafName()), this);
return new NumberFieldMapper(
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,
context.isSourceSynthetic(),
this
);
}
}

View file

@ -188,13 +188,13 @@ public class ObjectMapper extends Mapper {
@Override
public ObjectMapper build(MapperBuilderContext context) {
return new ObjectMapper(
name(),
context.buildFullName(name()),
leafName(),
context.buildFullName(leafName()),
enabled,
subobjects,
storeArraySource,
dynamic,
buildMappers(context.createChildContext(name(), dynamic))
buildMappers(context.createChildContext(leafName(), dynamic))
);
}
}
@ -325,7 +325,7 @@ public class ObjectMapper extends Mapper {
"Tried to add nested object ["
+ fieldName
+ "] to object ["
+ objBuilder.name()
+ objBuilder.leafName()
+ "] which does not support subobjects"
);
}
@ -660,7 +660,7 @@ public class ObjectMapper extends Mapper {
for (Mapper mapper : mappers.values()) {
if (mapper instanceof FieldMapper fieldMapper) {
FieldMapper.Builder fieldBuilder = fieldMapper.getMergeBuilder();
fieldBuilder.setName(path.pathAsText(mapper.simpleName()));
fieldBuilder.setLeafName(path.pathAsText(mapper.simpleName()));
flattenedMappers.add(fieldBuilder.build(context));
} else if (mapper instanceof ObjectMapper objectMapper) {
objectMapper.asFlattenedFieldMappers(context, flattenedMappers, path);

View file

@ -77,11 +77,11 @@ public class PassThroughObjectMapper extends ObjectMapper {
@Override
public PassThroughObjectMapper build(MapperBuilderContext context) {
return new PassThroughObjectMapper(
name(),
context.buildFullName(name()),
leafName(),
context.buildFullName(leafName()),
enabled,
dynamic,
buildMappers(context.createChildContext(name(), timeSeriesDimensionSubFields.value(), dynamic)),
buildMappers(context.createChildContext(leafName(), timeSeriesDimensionSubFields.value(), dynamic)),
timeSeriesDimensionSubFields,
priority
);

View file

@ -90,8 +90,8 @@ public class PlaceHolderFieldMapper extends FieldMapper {
@Override
public PlaceHolderFieldMapper build(MapperBuilderContext context) {
PlaceHolderFieldType mappedFieldType = new PlaceHolderFieldType(context.buildFullName(name()), type, Map.of());
return new PlaceHolderFieldMapper(name(), mappedFieldType, multiFieldsBuilder.build(this, context), copyTo, unknownParams);
PlaceHolderFieldType mappedFieldType = new PlaceHolderFieldType(context.buildFullName(leafName()), type, Map.of());
return new PlaceHolderFieldMapper(leafName(), mappedFieldType, multiFieldsBuilder.build(this, context), copyTo, unknownParams);
}
}

View file

@ -120,12 +120,12 @@ public class RangeFieldMapper extends FieldMapper {
}
protected RangeFieldType setupFieldType(MapperBuilderContext context) {
String fullName = context.buildFullName(name());
String fullName = context.buildFullName(leafName());
if (format.isConfigured()) {
if (type != RangeType.DATE) {
throw new IllegalArgumentException(
"field ["
+ name()
+ leafName()
+ "] of type [range]"
+ " should not define a dateTimeFormatter unless it is a "
+ RangeType.DATE
@ -167,7 +167,7 @@ public class RangeFieldMapper extends FieldMapper {
@Override
public RangeFieldMapper build(MapperBuilderContext context) {
RangeFieldType ft = setupFieldType(context);
return new RangeFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, type, this);
return new RangeFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, type, this);
}
}

View file

@ -108,7 +108,7 @@ public class RootObjectMapper extends ObjectMapper {
@Override
public RootObjectMapper build(MapperBuilderContext context) {
return new RootObjectMapper(
name(),
leafName(),
enabled,
subobjects,
storeArraySource,

View file

@ -374,18 +374,18 @@ public final class TextFieldMapper extends FieldMapper {
if (analyzers.positionIncrementGap.isConfigured()) {
if (fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
throw new IllegalArgumentException(
"Cannot set position_increment_gap on field [" + name() + "] without positions enabled"
"Cannot set position_increment_gap on field [" + leafName() + "] without positions enabled"
);
}
}
TextSearchInfo tsi = new TextSearchInfo(fieldType, similarity.getValue(), searchAnalyzer, searchQuoteAnalyzer);
TextFieldType ft;
if (indexCreatedVersion.isLegacyIndexVersion()) {
ft = new LegacyTextFieldType(context.buildFullName(name()), index.getValue(), store.getValue(), tsi, meta.getValue());
ft = new LegacyTextFieldType(context.buildFullName(leafName()), index.getValue(), store.getValue(), tsi, meta.getValue());
// ignore fieldData and eagerGlobalOrdinals
} else {
ft = new TextFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
index.getValue(),
store.getValue(),
tsi,
@ -407,7 +407,7 @@ public final class TextFieldMapper extends FieldMapper {
return null;
}
if (index.getValue() == false) {
throw new IllegalArgumentException("Cannot set index_prefixes on unindexed field [" + name() + "]");
throw new IllegalArgumentException("Cannot set index_prefixes on unindexed field [" + leafName() + "]");
}
/*
* Mappings before v7.2.1 use {@link Builder#name} instead of {@link Builder#fullName}
@ -416,7 +416,7 @@ public final class TextFieldMapper extends FieldMapper {
* or a multi-field). This way search will continue to work on old indices and new indices
* will use the expected full name.
*/
String fullName = indexCreatedVersion.before(IndexVersions.V_7_2_1) ? name() : context.buildFullName(name());
String fullName = indexCreatedVersion.before(IndexVersions.V_7_2_1) ? leafName() : context.buildFullName(leafName());
// Copy the index options of the main field to allow phrase queries on
// the prefix field.
FieldType pft = new FieldType(fieldType);
@ -448,10 +448,10 @@ public final class TextFieldMapper extends FieldMapper {
return null;
}
if (index.get() == false) {
throw new IllegalArgumentException("Cannot set index_phrases on unindexed field [" + name() + "]");
throw new IllegalArgumentException("Cannot set index_phrases on unindexed field [" + leafName() + "]");
}
if (fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
throw new IllegalArgumentException("Cannot set index_phrases on field [" + name() + "] if positions are not enabled");
throw new IllegalArgumentException("Cannot set index_phrases on field [" + leafName() + "] if positions are not enabled");
}
FieldType phraseFieldType = new FieldType(fieldType);
PhraseWrappedAnalyzer a = new PhraseWrappedAnalyzer(
@ -480,7 +480,7 @@ public final class TextFieldMapper extends FieldMapper {
throw new MapperParsingException("Cannot use reserved field name [" + mapper.name() + "]");
}
}
return new TextFieldMapper(name(), fieldType, tft, prefixFieldInfo, phraseFieldInfo, multiFields, copyTo, this);
return new TextFieldMapper(leafName(), fieldType, tft, prefixFieldInfo, phraseFieldInfo, multiFields, copyTo, this);
}
}

View file

@ -202,13 +202,13 @@ public final class FlattenedFieldMapper extends FieldMapper {
public FlattenedFieldMapper build(MapperBuilderContext context) {
MultiFields multiFields = multiFieldsBuilder.build(this, context);
if (multiFields.iterator().hasNext()) {
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name() + "] does not support [fields]");
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + leafName() + "] does not support [fields]");
}
if (copyTo.copyToFields().isEmpty() == false) {
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name() + "] does not support [copy_to]");
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + leafName() + "] does not support [copy_to]");
}
MappedFieldType ft = new RootFlattenedFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
hasDocValues.get(),
meta.get(),
@ -216,7 +216,7 @@ public final class FlattenedFieldMapper extends FieldMapper {
eagerGlobalOrdinals.get(),
dimensions.get()
);
return new FlattenedFieldMapper(name(), ft, this);
return new FlattenedFieldMapper(leafName(), ft, this);
}
}

View file

@ -245,9 +245,9 @@ public class DenseVectorFieldMapper extends FieldMapper {
@Override
public DenseVectorFieldMapper build(MapperBuilderContext context) {
return new DenseVectorFieldMapper(
name(),
leafName(),
new DenseVectorFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexVersionCreated,
elementType.getValue(),
dims.getValue(),

View file

@ -67,8 +67,8 @@ public class SparseVectorFieldMapper extends FieldMapper {
@Override
public SparseVectorFieldMapper build(MapperBuilderContext context) {
return new SparseVectorFieldMapper(
name(),
new SparseVectorFieldType(context.buildFullName(name()), meta.getValue()),
leafName(),
new SparseVectorFieldType(context.buildFullName(leafName()), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo
);

View file

@ -135,7 +135,7 @@ public class MappingLookupInferenceFieldMapperTests extends MapperServiceTestCas
@Override
public FieldMapper build(MapperBuilderContext context) {
return new TestInferenceFieldMapper(name());
return new TestInferenceFieldMapper(leafName());
}
}

View file

@ -64,7 +64,7 @@ public class NonDynamicFieldMapperTests extends NonDynamicFieldMapperTestCase {
@Override
public NonDynamicFieldMapper build(MapperBuilderContext context) {
return new NonDynamicFieldMapper(name(), new TextFieldMapper.TextFieldType(name(), false, true, meta.getValue()));
return new NonDynamicFieldMapper(leafName(), new TextFieldMapper.TextFieldType(leafName(), false, true, meta.getValue()));
}
}

View file

@ -176,7 +176,7 @@ public class ParametrizedMapperTests extends MapperServiceTestCase {
@Override
public FieldMapper build(MapperBuilderContext context) {
return new TestMapper(name(), context.buildFullName(name()), multiFieldsBuilder.build(this, context), copyTo, this);
return new TestMapper(leafName(), context.buildFullName(leafName()), multiFieldsBuilder.build(this, context), copyTo, this);
}
}

View file

@ -92,7 +92,7 @@ public class MockFieldMapper extends FieldMapper {
@Override
public MockFieldMapper build(MapperBuilderContext context) {
MultiFields multiFields = multiFieldsBuilder.build(this, context);
return new MockFieldMapper(name(), fieldType, multiFields, copyTo);
return new MockFieldMapper(leafName(), fieldType, multiFields, copyTo);
}
}
}

View file

@ -97,8 +97,8 @@ public class HistogramFieldMapper extends FieldMapper {
@Override
public HistogramFieldMapper build(MapperBuilderContext context) {
return new HistogramFieldMapper(
name(),
new HistogramFieldType(context.buildFullName(name()), meta.getValue()),
leafName(),
new HistogramFieldType(context.buildFullName(leafName()), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo,
this

View file

@ -146,16 +146,16 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
@Override
public SemanticTextFieldMapper build(MapperBuilderContext context) {
if (copyTo.copyToFields().isEmpty() == false) {
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name() + "] does not support [copy_to]");
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + leafName() + "] does not support [copy_to]");
}
if (multiFieldsBuilder.hasMultiFields()) {
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name() + "] does not support multi-fields");
throw new IllegalArgumentException(CONTENT_TYPE + " field [" + leafName() + "] does not support multi-fields");
}
final String fullName = context.buildFullName(name());
var childContext = context.createChildContext(name(), ObjectMapper.Dynamic.FALSE);
final String fullName = context.buildFullName(leafName());
var childContext = context.createChildContext(leafName(), ObjectMapper.Dynamic.FALSE);
final ObjectMapper inferenceField = inferenceFieldBuilder.apply(childContext);
return new SemanticTextFieldMapper(
name(),
leafName(),
new SemanticTextFieldType(
fullName,
inferenceId.getValue(),

View file

@ -143,7 +143,7 @@ public class AggregateDoubleMetricFieldMapper extends FieldMapper {
return parsedMetrics;
}, m -> toType(m).metrics, XContentBuilder::enumSet, Objects::toString).addValidator(v -> {
if (v == null || v.isEmpty()) {
throw new IllegalArgumentException("Property [" + Names.METRICS + "] is required for field [" + name() + "].");
throw new IllegalArgumentException("Property [" + Names.METRICS + "] is required for field [" + leafName() + "].");
}
});
@ -209,21 +209,23 @@ public class AggregateDoubleMetricFieldMapper extends FieldMapper {
}
if (metrics.getValue().contains(defaultMetric.getValue()) == false) {
throw new IllegalArgumentException("Property [" + Names.DEFAULT_METRIC + "] is required for field [" + name() + "].");
throw new IllegalArgumentException(
"Property [" + Names.DEFAULT_METRIC + "] is required for field [" + leafName() + "]."
);
}
}
if (metrics.getValue().contains(defaultMetric.getValue()) == false) {
// The default_metric is not defined in the "metrics" field
throw new IllegalArgumentException(
"Default metric [" + defaultMetric.getValue() + "] is not defined in the metrics of field [" + name() + "]."
"Default metric [" + defaultMetric.getValue() + "] is not defined in the metrics of field [" + leafName() + "]."
);
}
EnumMap<Metric, NumberFieldMapper> metricMappers = new EnumMap<>(Metric.class);
// Instantiate one NumberFieldMapper instance for each metric
for (Metric m : this.metrics.getValue()) {
String fieldName = subfieldName(name(), m);
String fieldName = subfieldName(leafName(), m);
NumberFieldMapper.Builder builder;
if (m == Metric.value_count) {
@ -259,14 +261,14 @@ public class AggregateDoubleMetricFieldMapper extends FieldMapper {
}, () -> new EnumMap<>(Metric.class)));
AggregateDoubleMetricFieldType metricFieldType = new AggregateDoubleMetricFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
meta.getValue(),
timeSeriesMetric.getValue()
);
metricFieldType.setMetricFields(metricFields);
metricFieldType.setDefaultMetric(defaultMetric.getValue());
return new AggregateDoubleMetricFieldMapper(name(), metricFieldType, metricMappers, this);
return new AggregateDoubleMetricFieldMapper(leafName(), metricFieldType, metricMappers, this);
}
}

View file

@ -110,8 +110,8 @@ public class ConstantKeywordFieldMapper extends FieldMapper {
);
}
return new ConstantKeywordFieldMapper(
name(),
new ConstantKeywordFieldType(context.buildFullName(name()), value.getValue(), meta.getValue())
leafName(),
new ConstantKeywordFieldType(context.buildFullName(leafName()), value.getValue(), meta.getValue())
);
}
}

View file

@ -290,16 +290,16 @@ public class CountedKeywordFieldMapper extends FieldMapper {
public FieldMapper build(MapperBuilderContext context) {
BinaryFieldMapper countFieldMapper = new BinaryFieldMapper.Builder(
name() + COUNT_FIELD_NAME_SUFFIX,
leafName() + COUNT_FIELD_NAME_SUFFIX,
context.isSourceSynthetic()
).docValues(true).build(context);
boolean isIndexed = indexed.getValue();
FieldType ft = isIndexed ? FIELD_TYPE_INDEXED : FIELD_TYPE_NOT_INDEXED;
return new CountedKeywordFieldMapper(
name(),
leafName(),
ft,
new CountedKeywordFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
isIndexed,
false,
true,

View file

@ -158,7 +158,7 @@ public class UnsignedLongFieldMapper extends FieldMapper {
parseUnsignedLong(o); // confirm that null_value is a proper unsigned_long
return (o instanceof BytesRef) ? ((BytesRef) o).utf8ToString() : o.toString();
} catch (Exception e) {
throw new MapperParsingException("Error parsing [null_value] on field [" + name() + "]: " + e.getMessage(), e);
throw new MapperParsingException("Error parsing [null_value] on field [" + leafName() + "]: " + e.getMessage(), e);
}
}
@ -200,7 +200,7 @@ public class UnsignedLongFieldMapper extends FieldMapper {
dimension.setValue(true);
}
UnsignedLongFieldType fieldType = new UnsignedLongFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.getValue(),
stored.getValue(),
hasDocValues.getValue(),
@ -211,7 +211,7 @@ public class UnsignedLongFieldMapper extends FieldMapper {
indexMode
);
return new UnsignedLongFieldMapper(
name(),
leafName(),
fieldType,
multiFieldsBuilder.build(this, context),
copyTo,

View file

@ -112,14 +112,14 @@ public class VersionStringFieldMapper extends FieldMapper {
}
private VersionStringFieldType buildFieldType(MapperBuilderContext context, FieldType fieldtype) {
return new VersionStringFieldType(context.buildFullName(name()), fieldtype, meta.getValue());
return new VersionStringFieldType(context.buildFullName(leafName()), fieldtype, meta.getValue());
}
@Override
public VersionStringFieldMapper build(MapperBuilderContext context) {
FieldType fieldtype = new FieldType(Defaults.FIELD_TYPE);
return new VersionStringFieldMapper(
name(),
leafName(),
fieldtype,
buildFieldType(context, fieldtype),
multiFieldsBuilder.build(this, context),

View file

@ -173,7 +173,7 @@ public class GeoShapeWithDocValuesFieldMapper extends AbstractShapeGeometryField
GeometryFieldScript.Factory factory = scriptCompiler.compile(this.script.get(), GeometryFieldScript.CONTEXT);
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> factory.newFactory(leafName(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
@ -194,7 +194,7 @@ public class GeoShapeWithDocValuesFieldMapper extends AbstractShapeGeometryField
);
GeoShapeParser parser = new GeoShapeParser(geometryParser, orientation.get().value());
GeoShapeWithDocValuesFieldType ft = new GeoShapeWithDocValuesFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
hasDocValues.get(),
stored.get(),
@ -206,7 +206,7 @@ public class GeoShapeWithDocValuesFieldMapper extends AbstractShapeGeometryField
);
if (script.get() == null) {
return new GeoShapeWithDocValuesFieldMapper(
name(),
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,
@ -216,7 +216,7 @@ public class GeoShapeWithDocValuesFieldMapper extends AbstractShapeGeometryField
);
}
return new GeoShapeWithDocValuesFieldMapper(
name(),
leafName(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,

View file

@ -105,14 +105,14 @@ public class PointFieldMapper extends AbstractPointGeometryFieldMapper<Cartesian
);
}
CartesianPointParser parser = new CartesianPointParser(
name(),
leafName(),
p -> CartesianPoint.parsePoint(p, ignoreZValue.get().value()),
nullValue.get(),
ignoreZValue.get().value(),
ignoreMalformed.get().value()
);
PointFieldType ft = new PointFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
stored.get(),
hasDocValues.get(),
@ -120,7 +120,7 @@ public class PointFieldMapper extends AbstractPointGeometryFieldMapper<Cartesian
nullValue.get(),
meta.get()
);
return new PointFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
return new PointFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
}
}

View file

@ -118,14 +118,14 @@ public class ShapeFieldMapper extends AbstractShapeGeometryFieldMapper<Geometry>
);
Parser<Geometry> parser = new ShapeParser(geometryParser);
ShapeFieldType ft = new ShapeFieldType(
context.buildFullName(name()),
context.buildFullName(leafName()),
indexed.get(),
hasDocValues.get(),
orientation.get().value(),
parser,
meta.get()
);
return new ShapeFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
return new ShapeFieldMapper(leafName(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
}
}

View file

@ -238,8 +238,14 @@ public class WildcardFieldMapper extends FieldMapper {
@Override
public WildcardFieldMapper build(MapperBuilderContext context) {
return new WildcardFieldMapper(
name(),
new WildcardFieldType(context.buildFullName(name()), nullValue.get(), ignoreAbove.get(), indexVersionCreated, meta.get()),
leafName(),
new WildcardFieldType(
context.buildFullName(leafName()),
nullValue.get(),
ignoreAbove.get(),
indexVersionCreated,
meta.get()
),
ignoreAbove.get(),
context.isSourceSynthetic(),
multiFieldsBuilder.build(this, context),