Skip to content

Commit db9a125

Browse files
authored
[8.x] Guard second doc parsing pass with index setting (#114649) (#114799)
* Guard second doc parsing pass with index setting (#114649) * Guard second doc parsing pass with index setting * add test * updates * updates * merge (cherry picked from commit 98e0a4e) * Update 21_synthetic_source_stored.yml
1 parent 684c66a commit db9a125

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/21_synthetic_source_stored.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,55 @@ index param - nested array within array:
411411
- match: { hits.hits.0._source.path.to.some.3.id: [ 1000, 2000 ] }
412412

413413

414+
---
415+
index param - nested array within array - disabled second pass:
416+
- requires:
417+
cluster_features: ["mapper.synthetic_source_keep"]
418+
reason: requires tracking ignored source
419+
420+
- do:
421+
indices.create:
422+
index: test
423+
body:
424+
settings:
425+
index:
426+
synthetic_source:
427+
enable_second_doc_parsing_pass: false
428+
mappings:
429+
_source:
430+
mode: synthetic
431+
properties:
432+
name:
433+
type: keyword
434+
path:
435+
properties:
436+
to:
437+
properties:
438+
some:
439+
synthetic_source_keep: arrays
440+
properties:
441+
id:
442+
type: integer
443+
444+
- do:
445+
bulk:
446+
index: test
447+
refresh: true
448+
body:
449+
- '{ "create": { } }'
450+
- '{ "name": "A", "path": [ { "to": [ { "some" : [ { "id": 10 }, { "id": [1, 3, 2] } ] }, { "some": { "id": 100 } } ] }, { "to": { "some": { "id": [1000, 2000] } } } ] }'
451+
- match: { errors: false }
452+
453+
- do:
454+
search:
455+
index: test
456+
sort: name
457+
- match: { hits.hits.0._source.name: A }
458+
- length: { hits.hits.0._source.path.to.some: 2}
459+
- match: { hits.hits.0._source.path.to.some.0.id: 10 }
460+
- match: { hits.hits.0._source.path.to.some.1.id: [ 1, 3, 2] }
461+
462+
414463
---
415464
# 112156
416465
stored field under object with store_array_source:

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
188188
FieldMapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING,
189189
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING,
190190
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING,
191+
IndexSettings.SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
191192
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING,
192193

193194
// validate that built-in similarities don't get redefined

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,13 @@ public Iterator<Setting<?>> settings() {
655655
Property.Final
656656
);
657657

658+
public static final Setting<Boolean> SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING = Setting.boolSetting(
659+
"index.synthetic_source.enable_second_doc_parsing_pass",
660+
true,
661+
Property.IndexScope,
662+
Property.Dynamic
663+
);
664+
658665
/**
659666
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code>
660667
*/
@@ -808,6 +815,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
808815
private volatile long mappingDimensionFieldsLimit;
809816
private volatile boolean skipIgnoredSourceWrite;
810817
private volatile boolean skipIgnoredSourceRead;
818+
private volatile boolean syntheticSourceSecondDocParsingPassEnabled;
811819
private final SourceFieldMapper.Mode indexMappingSourceMode;
812820

813821
/**
@@ -969,6 +977,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
969977
es87TSDBCodecEnabled = scopedSettings.get(TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING);
970978
skipIgnoredSourceWrite = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING);
971979
skipIgnoredSourceRead = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING);
980+
syntheticSourceSecondDocParsingPassEnabled = scopedSettings.get(SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING);
972981
indexMappingSourceMode = scopedSettings.get(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING);
973982

974983
scopedSettings.addSettingsUpdateConsumer(
@@ -1057,6 +1066,10 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
10571066
this::setSkipIgnoredSourceWrite
10581067
);
10591068
scopedSettings.addSettingsUpdateConsumer(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING, this::setSkipIgnoredSourceRead);
1069+
scopedSettings.addSettingsUpdateConsumer(
1070+
SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
1071+
this::setSyntheticSourceSecondDocParsingPassEnabled
1072+
);
10601073
}
10611074

10621075
private void setSearchIdleAfter(TimeValue searchIdleAfter) {
@@ -1649,6 +1662,14 @@ private void setSkipIgnoredSourceRead(boolean value) {
16491662
this.skipIgnoredSourceRead = value;
16501663
}
16511664

1665+
private void setSyntheticSourceSecondDocParsingPassEnabled(boolean syntheticSourceSecondDocParsingPassEnabled) {
1666+
this.syntheticSourceSecondDocParsingPassEnabled = syntheticSourceSecondDocParsingPassEnabled;
1667+
}
1668+
1669+
public boolean isSyntheticSourceSecondDocParsingPassEnabled() {
1670+
return syntheticSourceSecondDocParsingPassEnabled;
1671+
}
1672+
16521673
public SourceFieldMapper.Mode getIndexMappingSourceMode() {
16531674
return indexMappingSourceMode;
16541675
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public int get() {
111111
private final Set<String> ignoredFields;
112112
private final List<IgnoredSourceFieldMapper.NameValue> ignoredFieldValues;
113113
private final List<IgnoredSourceFieldMapper.NameValue> ignoredFieldsMissingValues;
114+
private final boolean inArrayScopeEnabled;
114115
private boolean inArrayScope;
115116

116117
private final Map<String, List<Mapper>> dynamicMappers;
@@ -143,6 +144,7 @@ private DocumentParserContext(
143144
Set<String> ignoreFields,
144145
List<IgnoredSourceFieldMapper.NameValue> ignoredFieldValues,
145146
List<IgnoredSourceFieldMapper.NameValue> ignoredFieldsWithNoSource,
147+
boolean inArrayScopeEnabled,
146148
boolean inArrayScope,
147149
Map<String, List<Mapper>> dynamicMappers,
148150
Map<String, ObjectMapper> dynamicObjectMappers,
@@ -164,6 +166,7 @@ private DocumentParserContext(
164166
this.ignoredFields = ignoreFields;
165167
this.ignoredFieldValues = ignoredFieldValues;
166168
this.ignoredFieldsMissingValues = ignoredFieldsWithNoSource;
169+
this.inArrayScopeEnabled = inArrayScopeEnabled;
167170
this.inArrayScope = inArrayScope;
168171
this.dynamicMappers = dynamicMappers;
169172
this.dynamicObjectMappers = dynamicObjectMappers;
@@ -188,6 +191,7 @@ private DocumentParserContext(ObjectMapper parent, ObjectMapper.Dynamic dynamic,
188191
in.ignoredFields,
189192
in.ignoredFieldValues,
190193
in.ignoredFieldsMissingValues,
194+
in.inArrayScopeEnabled,
191195
in.inArrayScope,
192196
in.dynamicMappers,
193197
in.dynamicObjectMappers,
@@ -219,6 +223,7 @@ protected DocumentParserContext(
219223
new HashSet<>(),
220224
new ArrayList<>(),
221225
new ArrayList<>(),
226+
mappingParserContext.getIndexSettings().isSyntheticSourceSecondDocParsingPassEnabled(),
222227
false,
223228
new HashMap<>(),
224229
new HashMap<>(),
@@ -371,7 +376,7 @@ public final Collection<IgnoredSourceFieldMapper.NameValue> getIgnoredFieldsMiss
371376
* Applies to synthetic source only.
372377
*/
373378
public final DocumentParserContext maybeCloneForArray(Mapper mapper) throws IOException {
374-
if (canAddIgnoredField() && mapper instanceof ObjectMapper) {
379+
if (canAddIgnoredField() && mapper instanceof ObjectMapper && inArrayScopeEnabled) {
375380
boolean isNested = mapper instanceof NestedObjectMapper;
376381
if ((inArrayScope == false && isNested == false) || (inArrayScope && isNested)) {
377382
DocumentParserContext subcontext = switchParser(parser());

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowActionTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public void testDynamicIndexSettingsAreClassified() {
333333
replicatedSettings.add(IndexSettings.MAX_SHINGLE_DIFF_SETTING);
334334
replicatedSettings.add(IndexSettings.TIME_SERIES_END_TIME);
335335
replicatedSettings.add(IndexSettings.PREFER_ILM_SETTING);
336+
replicatedSettings.add(IndexSettings.SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING);
336337
replicatedSettings.add(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING);
337338
replicatedSettings.add(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING);
338339
replicatedSettings.add(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING);

0 commit comments

Comments
 (0)