Skip to content

Commit e370194

Browse files
authored
Rollback of #98586 (#98805)
* Skip segment for MatchNoDocsQuery filters. When a query of a filter gets rewritten to MatchNoDocsQuery, segments will not produce any results. We can therefore skip processing such segments. This applies to FilterByFilterAggregator and FiltersAggregator, as well as to TermsAggregator when it uses StringTermsAggregatorFromFilters internally; the latter is an adapter aggregator to FilterByFilterAggregator. Fixes #94637 * Update docs/changelog/98295.yaml * Check all filters for `MatchNoDocsQuery`. * Skip optimization when 'other' bucket is requested. * Revert "Set default index mode for TimeSeries to `null` (#98586)" This reverts commit 56abb86.
1 parent bc1f256 commit e370194

File tree

7 files changed

+12
-53
lines changed

7 files changed

+12
-53
lines changed

docs/changelog/98586.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.elasticsearch.common.compress.CompressedXContent;
1212
import org.elasticsearch.index.IndexSettings;
13-
import org.elasticsearch.index.IndexVersion;
1413

1514
import java.util.List;
1615

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

37-
DocumentMapper(DocumentParser documentParser, Mapping mapping, CompressedXContent source, IndexVersion version) {
36+
DocumentMapper(DocumentParser documentParser, Mapping mapping, CompressedXContent source) {
3837
this.documentParser = documentParser;
3938
this.type = mapping.getRoot().name();
4039
this.mappingLookup = MappingLookup.fromMapping(mapping);
41-
if (sourceMapper().isSynthetic()
42-
&& source.string().contains("\"_source\":{\"mode\":\"synthetic\"}") == false
43-
&& version.onOrBefore(IndexVersion.V_8_10_0)) {
44-
/*
45-
* Indexes built at v.8.7 were missing an explicit entry for synthetic_source.
46-
* This got restored in v.8.9 (and patched in v.8.8) to avoid confusion. The change is only restricted to
47-
* mapping printout, it has no functional effect as the synthetic source already applies.
48-
*/
49-
this.mappingSource = mapping.toCompressedXContent();
50-
} else {
51-
assert mapping.toCompressedXContent().equals(source)
52-
: "provided source [" + source + "] differs from mapping [" + mapping.toCompressedXContent() + "]";
53-
this.mappingSource = source;
54-
}
40+
this.mappingSource = source;
41+
assert mapping.toCompressedXContent().equals(source)
42+
: "provided source [" + source + "] differs from mapping [" + mapping.toCompressedXContent() + "]";
5543
}
5644

5745
public Mapping mapping() {

server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public DocumentMapper merge(String type, CompressedXContent mappingSource, Merge
386386
}
387387

388388
private DocumentMapper newDocumentMapper(Mapping mapping, MergeReason reason, CompressedXContent mappingSource) {
389-
DocumentMapper newMapper = new DocumentMapper(documentParser, mapping, mappingSource, indexVersionCreated);
389+
DocumentMapper newMapper = new DocumentMapper(documentParser, mapping, mappingSource);
390390
newMapper.validate(indexSettings, reason != MergeReason.MAPPING_RECOVERY);
391391
return newMapper;
392392
}

server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,10 @@ public static class Builder extends MetadataFieldMapper.Builder {
8686
.setMergeValidator(
8787
(previous, current, conflicts) -> (previous.value() == current.value()) || (previous.value() && current.value() == false)
8888
);
89-
90-
/*
91-
* The default mode for TimeSeries is left empty on purpose, so that mapping printings include the synthetic
92-
* source mode.
93-
*/
9489
private final Parameter<Mode> mode = new Parameter<>(
9590
"mode",
9691
true,
97-
() -> null,
92+
() -> getIndexMode() == IndexMode.TIME_SERIES ? Mode.SYNTHETIC : null,
9893
(n, c, o) -> Mode.valueOf(o.toString().toUpperCase(Locale.ROOT)),
9994
m -> toType(m).enabled.explicit() ? null : toType(m).mode,
10095
(b, n, v) -> b.field(n, v.toString().toLowerCase(Locale.ROOT)),
@@ -141,11 +136,10 @@ private boolean isDefault() {
141136

142137
@Override
143138
public SourceFieldMapper build() {
144-
if (enabled.getValue().explicit()) {
139+
if (enabled.getValue().explicit() && mode.get() != null) {
145140
if (indexMode == IndexMode.TIME_SERIES) {
146141
throw new MapperParsingException("Time series indices only support synthetic source");
147-
}
148-
if (mode.get() != null) {
142+
} else {
149143
throw new MapperParsingException("Cannot set both [mode] and [enabled] parameters");
150144
}
151145
}
@@ -223,7 +217,7 @@ private SourceFieldMapper(Mode mode, Explicit<Boolean> enabled, String[] include
223217
this.sourceFilter = buildSourceFilter(includes, excludes);
224218
this.includes = includes;
225219
this.excludes = excludes;
226-
if (this.sourceFilter != null && (mode == Mode.SYNTHETIC || indexMode == IndexMode.TIME_SERIES)) {
220+
if (this.sourceFilter != null && mode == Mode.SYNTHETIC) {
227221
throw new IllegalArgumentException("filtering the stored _source is incompatible with synthetic source");
228222
}
229223
this.complete = stored() && sourceFilter == null;

server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testAddFields() throws Exception {
6969
assertThat(stage1.mappers().getMapper("obj1.prop1"), nullValue());
7070
// but merged should
7171
DocumentParser documentParser = new DocumentParser(null, null, () -> DocumentParsingObserver.EMPTY_INSTANCE);
72-
DocumentMapper mergedMapper = new DocumentMapper(documentParser, merged, merged.toCompressedXContent(), IndexVersion.current());
72+
DocumentMapper mergedMapper = new DocumentMapper(documentParser, merged, merged.toCompressedXContent());
7373
assertThat(mergedMapper.mappers().getMapper("age"), notNullValue());
7474
assertThat(mergedMapper.mappers().getMapper("obj1.prop1"), notNullValue());
7575
}

server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.elasticsearch.common.bytes.BytesReference;
2121
import org.elasticsearch.common.settings.Settings;
2222
import org.elasticsearch.index.IndexSettings;
23-
import org.elasticsearch.index.IndexVersion;
2423
import org.elasticsearch.plugins.MapperPlugin;
2524
import org.elasticsearch.plugins.Plugin;
2625
import org.elasticsearch.script.CompositeFieldScript;
@@ -2531,12 +2530,7 @@ same name need to be part of the same mappings (hence the same document). If th
25312530

25322531
// merge without going through toXContent and reparsing, otherwise the potential leaf path issue gets fixed on its own
25332532
Mapping newMapping = MapperService.mergeMappings(mapperService.documentMapper(), mapping, MapperService.MergeReason.MAPPING_UPDATE);
2534-
DocumentMapper newDocMapper = new DocumentMapper(
2535-
mapperService.documentParser(),
2536-
newMapping,
2537-
newMapping.toCompressedXContent(),
2538-
IndexVersion.current()
2539-
);
2533+
DocumentMapper newDocMapper = new DocumentMapper(mapperService.documentParser(), newMapping, newMapping.toCompressedXContent());
25402534
ParsedDocument doc2 = newDocMapper.parse(source("""
25412535
{
25422536
"foo" : {

server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.bytes.BytesArray;
1313
import org.elasticsearch.common.bytes.BytesReference;
1414
import org.elasticsearch.common.xcontent.XContentHelper;
15-
import org.elasticsearch.xcontent.XContentBuilder;
1615
import org.elasticsearch.xcontent.XContentFactory;
1716
import org.elasticsearch.xcontent.XContentParser;
1817
import org.elasticsearch.xcontent.XContentType;
@@ -228,14 +227,4 @@ public void testSyntheticUpdates() throws Exception {
228227
assertFalse(mapper.enabled());
229228
assertFalse(mapper.isSynthetic());
230229
}
231-
232-
public void testSyntheticSourceInTimeSeries() throws IOException {
233-
XContentBuilder mapping = fieldMapping(b -> {
234-
b.field("type", "keyword");
235-
b.field("time_series_dimension", true);
236-
});
237-
DocumentMapper mapper = createTimeSeriesModeDocumentMapper(mapping);
238-
assertTrue(mapper.sourceMapper().isSynthetic());
239-
assertEquals("{\"_source\":{\"mode\":\"synthetic\"}}", mapper.sourceMapper().toString());
240-
}
241230
}

0 commit comments

Comments
 (0)