Skip to content

Commit 98e0a4e

Browse files
authored
Guard second doc parsing pass with index setting (#114649)
* Guard second doc parsing pass with index setting * add test * updates * updates * merge
1 parent 4ab2e61 commit 98e0a4e

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", "mapper.bwc_workaround_9_0"]
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
@@ -187,6 +187,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
187187
FieldMapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING,
188188
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING,
189189
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING,
190+
IndexSettings.SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
190191
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING,
191192

192193
// 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
@@ -652,6 +652,13 @@ public Iterator<Setting<?>> settings() {
652652
Property.Final
653653
);
654654

655+
public static final Setting<Boolean> SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING = Setting.boolSetting(
656+
"index.synthetic_source.enable_second_doc_parsing_pass",
657+
true,
658+
Property.IndexScope,
659+
Property.Dynamic
660+
);
661+
655662
/**
656663
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code>
657664
*/
@@ -821,6 +828,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
821828
private volatile long mappingDimensionFieldsLimit;
822829
private volatile boolean skipIgnoredSourceWrite;
823830
private volatile boolean skipIgnoredSourceRead;
831+
private volatile boolean syntheticSourceSecondDocParsingPassEnabled;
824832
private final SourceFieldMapper.Mode indexMappingSourceMode;
825833

826834
/**
@@ -982,6 +990,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
982990
es87TSDBCodecEnabled = scopedSettings.get(TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING);
983991
skipIgnoredSourceWrite = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING);
984992
skipIgnoredSourceRead = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING);
993+
syntheticSourceSecondDocParsingPassEnabled = scopedSettings.get(SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING);
985994
indexMappingSourceMode = scopedSettings.get(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING);
986995

987996
scopedSettings.addSettingsUpdateConsumer(
@@ -1070,6 +1079,10 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
10701079
this::setSkipIgnoredSourceWrite
10711080
);
10721081
scopedSettings.addSettingsUpdateConsumer(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING, this::setSkipIgnoredSourceRead);
1082+
scopedSettings.addSettingsUpdateConsumer(
1083+
SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
1084+
this::setSyntheticSourceSecondDocParsingPassEnabled
1085+
);
10731086
}
10741087

10751088
private void setSearchIdleAfter(TimeValue searchIdleAfter) {
@@ -1662,6 +1675,14 @@ private void setSkipIgnoredSourceRead(boolean value) {
16621675
this.skipIgnoredSourceRead = value;
16631676
}
16641677

1678+
private void setSyntheticSourceSecondDocParsingPassEnabled(boolean syntheticSourceSecondDocParsingPassEnabled) {
1679+
this.syntheticSourceSecondDocParsingPassEnabled = syntheticSourceSecondDocParsingPassEnabled;
1680+
}
1681+
1682+
public boolean isSyntheticSourceSecondDocParsingPassEnabled() {
1683+
return syntheticSourceSecondDocParsingPassEnabled;
1684+
}
1685+
16651686
public SourceFieldMapper.Mode getIndexMappingSourceMode() {
16661687
return indexMappingSourceMode;
16671688
}

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)