Skip to content

Commit

Permalink
Guard second doc parsing pass with index setting (elastic#114649)
Browse files Browse the repository at this point in the history
* Guard second doc parsing pass with index setting

* add test

* updates

* updates

* merge
  • Loading branch information
kkrik-es authored Oct 14, 2024
1 parent 4ab2e61 commit 98e0a4e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,55 @@ index param - nested array within array:
- match: { hits.hits.0._source.path.to.some.3.id: [ 1000, 2000 ] }


---
index param - nested array within array - disabled second pass:
- requires:
cluster_features: ["mapper.synthetic_source_keep", "mapper.bwc_workaround_9_0"]
reason: requires tracking ignored source

- do:
indices.create:
index: test
body:
settings:
index:
synthetic_source:
enable_second_doc_parsing_pass: false
mappings:
_source:
mode: synthetic
properties:
name:
type: keyword
path:
properties:
to:
properties:
some:
synthetic_source_keep: arrays
properties:
id:
type: integer

- do:
bulk:
index: test
refresh: true
body:
- '{ "create": { } }'
- '{ "name": "A", "path": [ { "to": [ { "some" : [ { "id": 10 }, { "id": [1, 3, 2] } ] }, { "some": { "id": 100 } } ] }, { "to": { "some": { "id": [1000, 2000] } } } ] }'
- match: { errors: false }

- do:
search:
index: test
sort: name
- match: { hits.hits.0._source.name: A }
- length: { hits.hits.0._source.path.to.some: 2}
- match: { hits.hits.0._source.path.to.some.0.id: 10 }
- match: { hits.hits.0._source.path.to.some.1.id: [ 1, 3, 2] }


---
# 112156
stored field under object with store_array_source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
FieldMapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING,
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING,
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING,
IndexSettings.SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING,

// validate that built-in similarities don't get redefined
Expand Down
21 changes: 21 additions & 0 deletions server/src/main/java/org/elasticsearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ public Iterator<Setting<?>> settings() {
Property.Final
);

public static final Setting<Boolean> SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING = Setting.boolSetting(
"index.synthetic_source.enable_second_doc_parsing_pass",
true,
Property.IndexScope,
Property.Dynamic
);

/**
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code>
*/
Expand Down Expand Up @@ -821,6 +828,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
private volatile long mappingDimensionFieldsLimit;
private volatile boolean skipIgnoredSourceWrite;
private volatile boolean skipIgnoredSourceRead;
private volatile boolean syntheticSourceSecondDocParsingPassEnabled;
private final SourceFieldMapper.Mode indexMappingSourceMode;

/**
Expand Down Expand Up @@ -982,6 +990,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
es87TSDBCodecEnabled = scopedSettings.get(TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING);
skipIgnoredSourceWrite = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING);
skipIgnoredSourceRead = scopedSettings.get(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING);
syntheticSourceSecondDocParsingPassEnabled = scopedSettings.get(SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING);
indexMappingSourceMode = scopedSettings.get(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING);

scopedSettings.addSettingsUpdateConsumer(
Expand Down Expand Up @@ -1070,6 +1079,10 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
this::setSkipIgnoredSourceWrite
);
scopedSettings.addSettingsUpdateConsumer(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING, this::setSkipIgnoredSourceRead);
scopedSettings.addSettingsUpdateConsumer(
SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING,
this::setSyntheticSourceSecondDocParsingPassEnabled
);
}

private void setSearchIdleAfter(TimeValue searchIdleAfter) {
Expand Down Expand Up @@ -1662,6 +1675,14 @@ private void setSkipIgnoredSourceRead(boolean value) {
this.skipIgnoredSourceRead = value;
}

private void setSyntheticSourceSecondDocParsingPassEnabled(boolean syntheticSourceSecondDocParsingPassEnabled) {
this.syntheticSourceSecondDocParsingPassEnabled = syntheticSourceSecondDocParsingPassEnabled;
}

public boolean isSyntheticSourceSecondDocParsingPassEnabled() {
return syntheticSourceSecondDocParsingPassEnabled;
}

public SourceFieldMapper.Mode getIndexMappingSourceMode() {
return indexMappingSourceMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public int get() {
private final Set<String> ignoredFields;
private final List<IgnoredSourceFieldMapper.NameValue> ignoredFieldValues;
private final List<IgnoredSourceFieldMapper.NameValue> ignoredFieldsMissingValues;
private final boolean inArrayScopeEnabled;
private boolean inArrayScope;

private final Map<String, List<Mapper>> dynamicMappers;
Expand Down Expand Up @@ -143,6 +144,7 @@ private DocumentParserContext(
Set<String> ignoreFields,
List<IgnoredSourceFieldMapper.NameValue> ignoredFieldValues,
List<IgnoredSourceFieldMapper.NameValue> ignoredFieldsWithNoSource,
boolean inArrayScopeEnabled,
boolean inArrayScope,
Map<String, List<Mapper>> dynamicMappers,
Map<String, ObjectMapper> dynamicObjectMappers,
Expand All @@ -164,6 +166,7 @@ private DocumentParserContext(
this.ignoredFields = ignoreFields;
this.ignoredFieldValues = ignoredFieldValues;
this.ignoredFieldsMissingValues = ignoredFieldsWithNoSource;
this.inArrayScopeEnabled = inArrayScopeEnabled;
this.inArrayScope = inArrayScope;
this.dynamicMappers = dynamicMappers;
this.dynamicObjectMappers = dynamicObjectMappers;
Expand All @@ -188,6 +191,7 @@ private DocumentParserContext(ObjectMapper parent, ObjectMapper.Dynamic dynamic,
in.ignoredFields,
in.ignoredFieldValues,
in.ignoredFieldsMissingValues,
in.inArrayScopeEnabled,
in.inArrayScope,
in.dynamicMappers,
in.dynamicObjectMappers,
Expand Down Expand Up @@ -219,6 +223,7 @@ protected DocumentParserContext(
new HashSet<>(),
new ArrayList<>(),
new ArrayList<>(),
mappingParserContext.getIndexSettings().isSyntheticSourceSecondDocParsingPassEnabled(),
false,
new HashMap<>(),
new HashMap<>(),
Expand Down Expand Up @@ -371,7 +376,7 @@ public final Collection<IgnoredSourceFieldMapper.NameValue> getIgnoredFieldsMiss
* Applies to synthetic source only.
*/
public final DocumentParserContext maybeCloneForArray(Mapper mapper) throws IOException {
if (canAddIgnoredField() && mapper instanceof ObjectMapper) {
if (canAddIgnoredField() && mapper instanceof ObjectMapper && inArrayScopeEnabled) {
boolean isNested = mapper instanceof NestedObjectMapper;
if ((inArrayScope == false && isNested == false) || (inArrayScope && isNested)) {
DocumentParserContext subcontext = switchParser(parser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public void testDynamicIndexSettingsAreClassified() {
replicatedSettings.add(IndexSettings.MAX_SHINGLE_DIFF_SETTING);
replicatedSettings.add(IndexSettings.TIME_SERIES_END_TIME);
replicatedSettings.add(IndexSettings.PREFER_ILM_SETTING);
replicatedSettings.add(IndexSettings.SYNTHETIC_SOURCE_SECOND_DOC_PARSING_PASS_SETTING);
replicatedSettings.add(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING);
replicatedSettings.add(IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING);
replicatedSettings.add(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING);
Expand Down

0 comments on commit 98e0a4e

Please sign in to comment.