Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/137297.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137297
summary: Fixed inconsistency in the `isSyntheticSourceEnabled` flag
area: Mapping
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static class Defaults {

}

public static class Builder extends BuilderWithSyntheticSourceContext {
public static class Builder extends TextFamilyBuilder {

private final Parameter<Map<String, String>> meta = Parameter.metaParam();

Expand All @@ -112,10 +112,9 @@ public Builder(
IndexVersion indexCreatedVersion,
IndexAnalyzers indexAnalyzers,
boolean storedFieldInBinaryFormat,
boolean isSyntheticSourceEnabled,
boolean isWithinMultiField
) {
super(name, indexCreatedVersion, isSyntheticSourceEnabled, isWithinMultiField);
super(name, indexCreatedVersion, isWithinMultiField);
this.analyzers = new TextParams.Analyzers(
indexAnalyzers,
m -> ((MatchOnlyTextFieldMapper) m).indexAnalyzer,
Expand Down Expand Up @@ -169,7 +168,6 @@ private static boolean isSyntheticSourceStoredFieldInBinaryFormat(IndexVersion i
n,
c.indexVersionCreated(),
c.getIndexAnalyzers(),
isSyntheticSourceStoredFieldInBinaryFormat(c.indexVersionCreated()),
SourceFieldMapper.isSynthetic(c.getIndexSettings()),
c.isWithinMultiField()
)
Expand Down Expand Up @@ -677,14 +675,8 @@ public Map<String, NamedAnalyzer> indexAnalyzers() {

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(
leafName(),
indexCreatedVersion,
indexAnalyzers,
storedFieldInBinaryFormat,
fieldType().isSyntheticSourceEnabled(),
fieldType().isWithinMultiField()
).init(this);
return new Builder(leafName(), indexCreatedVersion, indexAnalyzers, storedFieldInBinaryFormat, fieldType().isWithinMultiField())
.init(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static NamedAnalyzer wrapAnalyzer(NamedAnalyzer in) {
);
}

public static class Builder extends BuilderWithSyntheticSourceContext {
public static class Builder extends TextFamilyBuilder {

final Parameter<SimilarityProvider> similarity = TextParams.similarity(m -> builder(m).similarity.getValue());
final Parameter<String> indexOptions = TextParams.textIndexOptions(m -> builder(m).indexOptions.getValue());
Expand All @@ -100,7 +100,7 @@ public Builder(
boolean isSyntheticSourceEnabled,
boolean isWithinMultiField
) {
super(name, indexCreatedVersion, isSyntheticSourceEnabled, isWithinMultiField);
super(name, indexCreatedVersion, isWithinMultiField);
this.analyzers = new TextParams.Analyzers(
indexAnalyzers,
m -> builder(m).analyzers.getIndexAnalyzer(),
Expand All @@ -111,7 +111,7 @@ public Builder(
if (TextFieldMapper.keywordMultiFieldsNotStoredWhenIgnoredIndexVersionCheck(indexCreatedVersion())) {
return false;
}
return isSyntheticSourceEnabled() && multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
return isSyntheticSourceEnabled && multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1663,32 +1663,21 @@ protected boolean inheritDimensionParameterFromParentObject(MapperBuilderContext
/**
* Creates mappers for fields that require additional context for supporting synthetic source.
*/
public abstract static class BuilderWithSyntheticSourceContext extends Builder {
public abstract static class TextFamilyBuilder extends Builder {

private final IndexVersion indexCreatedVersion;
private final boolean isSyntheticSourceEnabled;
private final boolean isWithinMultiField;

protected BuilderWithSyntheticSourceContext(
String name,
IndexVersion indexCreatedVersion,
boolean isSyntheticSourceEnabled,
boolean isWithinMultiField
) {
protected TextFamilyBuilder(String name, IndexVersion indexCreatedVersion, boolean isWithinMultiField) {
super(name);
this.indexCreatedVersion = indexCreatedVersion;
this.isSyntheticSourceEnabled = isSyntheticSourceEnabled;
this.isWithinMultiField = isWithinMultiField;
}

public IndexVersion indexCreatedVersion() {
return indexCreatedVersion;
}

public boolean isSyntheticSourceEnabled() {
return isSyntheticSourceEnabled;
}

public boolean isWithinMultiField() {
return isWithinMultiField;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ public boolean isSynthetic() {
return mode == Mode.SYNTHETIC;
}

/**
* Caution: this function is not aware of the legacy "mappings._source.mode" parameter that some legacy indices might use. You should
* prefer to get information about synthetic source from {@link MapperBuilderContext}.
*/
public static boolean isSynthetic(IndexSettings indexSettings) {
return IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexSettings.getSettings()) == SourceFieldMapper.Mode.SYNTHETIC;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private static FielddataFrequencyFilter parseFrequencyFilter(String name, Mappin
return new FielddataFrequencyFilter(minFrequency, maxFrequency, minSegmentSize);
}

public static class Builder extends BuilderWithSyntheticSourceContext {
public static class Builder extends TextFamilyBuilder {

private final Parameter<Boolean> store;
private final Parameter<Boolean> norms;
Expand Down Expand Up @@ -301,7 +301,7 @@ public Builder(
boolean isSyntheticSourceEnabled,
boolean isWithinMultiField
) {
super(name, indexCreatedVersion, isSyntheticSourceEnabled, isWithinMultiField);
super(name, indexCreatedVersion, isWithinMultiField);

this.indexMode = indexMode;
this.analyzers = new TextParams.Analyzers(
Expand Down Expand Up @@ -409,7 +409,7 @@ private TextFieldType buildFieldType(
index.getValue(),
store.getValue(),
tsi,
isSyntheticSourceEnabled(),
context.isSourceSynthetic(),
isWithinMultiField(),
SyntheticSourceHelper.syntheticSourceDelegate(fieldType.stored(), multiFields),
meta.getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MappingParserContext;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.StringStoredFieldFieldLoader;
import org.elasticsearch.index.mapper.TextParams;
Expand Down Expand Up @@ -88,7 +87,7 @@ public static class Defaults {
}
}

public static class Builder extends BuilderWithSyntheticSourceContext {
public static class Builder extends TextFamilyBuilder {

private final IndexSettings indexSettings;
private final Parameter<Map<String, String>> meta = Parameter.metaParam();
Expand All @@ -97,23 +96,11 @@ public static class Builder extends BuilderWithSyntheticSourceContext {
private final Parameter<Boolean> disableTemplating;

public Builder(String name, MappingParserContext context) {
this(
name,
context.indexVersionCreated(),
context.getIndexSettings(),
SourceFieldMapper.isSynthetic(context.getIndexSettings()),
context.isWithinMultiField()
);
this(name, context.indexVersionCreated(), context.getIndexSettings(), context.isWithinMultiField());
}

public Builder(
String name,
IndexVersion indexCreatedVersion,
IndexSettings indexSettings,
boolean isSyntheticSourceEnabled,
boolean isWithinMultiField
) {
super(name, indexCreatedVersion, isSyntheticSourceEnabled, isWithinMultiField);
public Builder(String name, IndexVersion indexCreatedVersion, IndexSettings indexSettings, boolean isWithinMultiField) {
super(name, indexCreatedVersion, isWithinMultiField);
this.indexSettings = indexSettings;
this.analyzer = analyzerParam(name, m -> ((PatternTextFieldMapper) m).analyzer);
this.disableTemplating = disableTemplatingParameter(indexSettings);
Expand Down Expand Up @@ -249,13 +236,7 @@ public Map<String, NamedAnalyzer> indexAnalyzers() {

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(
leafName(),
indexCreatedVersion,
indexSettings,
fieldType().isSyntheticSourceEnabled(),
fieldType().isWithinMultiField()
).init(this);
return new Builder(leafName(), indexCreatedVersion, indexSettings, fieldType().isWithinMultiField()).init(this);
}

@Override
Expand Down