Skip to content

[8.10] Rollback of #98586 (#98805) #98806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
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
6 changes: 0 additions & 6 deletions docs/changelog/98586.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;

import java.util.List;

Expand All @@ -31,27 +30,16 @@ public static DocumentMapper createEmpty(MapperService mapperService) {
);
MetadataFieldMapper[] metadata = mapperService.getMetadataMappers().values().toArray(new MetadataFieldMapper[0]);
Mapping mapping = new Mapping(root, metadata, null);
return new DocumentMapper(mapperService.documentParser(), mapping, mapping.toCompressedXContent(), IndexVersion.current());
return new DocumentMapper(mapperService.documentParser(), mapping, mapping.toCompressedXContent());
}

DocumentMapper(DocumentParser documentParser, Mapping mapping, CompressedXContent source, IndexVersion version) {
DocumentMapper(DocumentParser documentParser, Mapping mapping, CompressedXContent source) {
this.documentParser = documentParser;
this.type = mapping.getRoot().name();
this.mappingLookup = MappingLookup.fromMapping(mapping);
if (sourceMapper().isSynthetic()
&& source.string().contains("\"_source\":{\"mode\":\"synthetic\"}") == false
&& version.onOrBefore(IndexVersion.V_8_10_0)) {
/*
* Indexes built at v.8.7 were missing an explicit entry for synthetic_source.
* This got restored in v.8.9 (and patched in v.8.8) to avoid confusion. The change is only restricted to
* mapping printout, it has no functional effect as the synthetic source already applies.
*/
this.mappingSource = mapping.toCompressedXContent();
} else {
assert mapping.toCompressedXContent().equals(source)
: "provided source [" + source + "] differs from mapping [" + mapping.toCompressedXContent() + "]";
this.mappingSource = source;
}
this.mappingSource = source;
assert mapping.toCompressedXContent().equals(source)
: "provided source [" + source + "] differs from mapping [" + mapping.toCompressedXContent() + "]";
}

public Mapping mapping() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public DocumentMapper merge(String type, CompressedXContent mappingSource, Merge
}

private DocumentMapper newDocumentMapper(Mapping mapping, MergeReason reason, CompressedXContent mappingSource) {
DocumentMapper newMapper = new DocumentMapper(documentParser, mapping, mappingSource, indexVersionCreated);
DocumentMapper newMapper = new DocumentMapper(documentParser, mapping, mappingSource);
newMapper.validate(indexSettings, reason != MergeReason.MAPPING_RECOVERY);
return newMapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@ public static class Builder extends MetadataFieldMapper.Builder {
.setMergeValidator(
(previous, current, conflicts) -> (previous.value() == current.value()) || (previous.value() && current.value() == false)
);

/*
* The default mode for TimeSeries is left empty on purpose, so that mapping printings include the synthetic
* source mode.
*/
private final Parameter<Mode> mode = new Parameter<>(
"mode",
true,
() -> null,
() -> getIndexMode() == IndexMode.TIME_SERIES ? Mode.SYNTHETIC : null,
(n, c, o) -> Mode.valueOf(o.toString().toUpperCase(Locale.ROOT)),
m -> toType(m).enabled.explicit() ? null : toType(m).mode,
(b, n, v) -> b.field(n, v.toString().toLowerCase(Locale.ROOT)),
Expand Down Expand Up @@ -141,11 +136,10 @@ private boolean isDefault() {

@Override
public SourceFieldMapper build() {
if (enabled.getValue().explicit()) {
if (enabled.getValue().explicit() && mode.get() != null) {
if (indexMode == IndexMode.TIME_SERIES) {
throw new MapperParsingException("Time series indices only support synthetic source");
}
if (mode.get() != null) {
} else {
throw new MapperParsingException("Cannot set both [mode] and [enabled] parameters");
}
}
Expand Down Expand Up @@ -223,7 +217,7 @@ private SourceFieldMapper(Mode mode, Explicit<Boolean> enabled, String[] include
this.sourceFilter = buildSourceFilter(includes, excludes);
this.includes = includes;
this.excludes = excludes;
if (this.sourceFilter != null && (mode == Mode.SYNTHETIC || indexMode == IndexMode.TIME_SERIES)) {
if (this.sourceFilter != null && mode == Mode.SYNTHETIC) {
throw new IllegalArgumentException("filtering the stored _source is incompatible with synthetic source");
}
this.complete = stored() && sourceFilter == null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testAddFields() throws Exception {
assertThat(stage1.mappers().getMapper("obj1.prop1"), nullValue());
// but merged should
DocumentParser documentParser = new DocumentParser(null, null, () -> DocumentParsingObserver.EMPTY_INSTANCE);
DocumentMapper mergedMapper = new DocumentMapper(documentParser, merged, merged.toCompressedXContent(), IndexVersion.current());
DocumentMapper mergedMapper = new DocumentMapper(documentParser, merged, merged.toCompressedXContent());
assertThat(mergedMapper.mappers().getMapper("age"), notNullValue());
assertThat(mergedMapper.mappers().getMapper("obj1.prop1"), notNullValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.CompositeFieldScript;
Expand Down Expand Up @@ -2531,12 +2530,7 @@ same name need to be part of the same mappings (hence the same document). If th

// merge without going through toXContent and reparsing, otherwise the potential leaf path issue gets fixed on its own
Mapping newMapping = MapperService.mergeMappings(mapperService.documentMapper(), mapping, MapperService.MergeReason.MAPPING_UPDATE);
DocumentMapper newDocMapper = new DocumentMapper(
mapperService.documentParser(),
newMapping,
newMapping.toCompressedXContent(),
IndexVersion.current()
);
DocumentMapper newDocMapper = new DocumentMapper(mapperService.documentParser(), newMapping, newMapping.toCompressedXContent());
ParsedDocument doc2 = newDocMapper.parse(source("""
{
"foo" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
Expand Down Expand Up @@ -228,14 +227,4 @@ public void testSyntheticUpdates() throws Exception {
assertFalse(mapper.enabled());
assertFalse(mapper.isSynthetic());
}

public void testSyntheticSourceInTimeSeries() throws IOException {
XContentBuilder mapping = fieldMapping(b -> {
b.field("type", "keyword");
b.field("time_series_dimension", true);
});
DocumentMapper mapper = createTimeSeriesModeDocumentMapper(mapping);
assertTrue(mapper.sourceMapper().isSynthetic());
assertEquals("{\"_source\":{\"mode\":\"synthetic\"}}", mapper.sourceMapper().toString());
}
}