Skip to content

Commit 8001252

Browse files
committed
update
1 parent a455a4a commit 8001252

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
133133
IndexSettings.MAX_RESCORE_WINDOW_SETTING,
134134
IndexSettings.MAX_ANALYZED_OFFSET_SETTING,
135135
IndexSettings.WEIGHT_MATCHES_MODE_ENABLED_SETTING,
136+
IndexSettings.MAX_SOURCE_SIZE_BYTES_SETTING,
136137
IndexSettings.MAX_TERMS_COUNT_SETTING,
137138
IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING,
138139
IndexSettings.DEFAULT_FIELD_SETTING,

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ public final class IndexSettings {
209209
Property.IndexScope
210210
);
211211

212+
public static final Setting<Integer> MAX_SOURCE_SIZE_BYTES_SETTING = Setting.intSetting(
213+
"index.max_source_size_bytes",
214+
500000,
215+
1,
216+
Property.Dynamic,
217+
Property.IndexScope
218+
);
219+
212220
/**
213221
* Index setting describing the maximum number of terms that can be used in Terms Query.
214222
* The default maximum of 65536 terms is defensive, as extra processing and memory is involved
@@ -919,6 +927,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
919927
private volatile TimeValue searchIdleAfter;
920928
private volatile int maxAnalyzedOffset;
921929
private volatile boolean weightMatchesEnabled;
930+
private volatile int maxSourceSizeBytes;
922931
private volatile int maxTermsCount;
923932
private volatile String defaultPipeline;
924933
private volatile String requiredPipeline;
@@ -1091,6 +1100,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
10911100
maxSlicesPerScroll = scopedSettings.get(MAX_SLICES_PER_SCROLL);
10921101
maxAnalyzedOffset = scopedSettings.get(MAX_ANALYZED_OFFSET_SETTING);
10931102
weightMatchesEnabled = scopedSettings.get(WEIGHT_MATCHES_MODE_ENABLED_SETTING);
1103+
maxSourceSizeBytes = scopedSettings.get(MAX_SOURCE_SIZE_BYTES_SETTING);
10941104
maxTermsCount = scopedSettings.get(MAX_TERMS_COUNT_SETTING);
10951105
maxRegexLength = scopedSettings.get(MAX_REGEX_LENGTH_SETTING);
10961106
this.mergePolicyConfig = new MergePolicyConfig(logger, this);
@@ -1202,6 +1212,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
12021212
scopedSettings.addSettingsUpdateConsumer(MAX_REFRESH_LISTENERS_PER_SHARD, this::setMaxRefreshListeners);
12031213
scopedSettings.addSettingsUpdateConsumer(MAX_ANALYZED_OFFSET_SETTING, this::setHighlightMaxAnalyzedOffset);
12041214
scopedSettings.addSettingsUpdateConsumer(WEIGHT_MATCHES_MODE_ENABLED_SETTING, this::setWeightMatchesEnabled);
1215+
scopedSettings.addSettingsUpdateConsumer(MAX_SOURCE_SIZE_BYTES_SETTING, this::setMaxSourceSizeBytes);
12051216
scopedSettings.addSettingsUpdateConsumer(MAX_TERMS_COUNT_SETTING, this::setMaxTermsCount);
12061217
scopedSettings.addSettingsUpdateConsumer(MAX_SLICES_PER_SCROLL, this::setMaxSlicesPerScroll);
12071218
scopedSettings.addSettingsUpdateConsumer(DEFAULT_FIELD_SETTING, this::setDefaultFields);
@@ -1603,6 +1614,17 @@ private void setWeightMatchesEnabled(boolean value) {
16031614
this.weightMatchesEnabled = value;
16041615
}
16051616

1617+
/**
1618+
* Returns the maximum number of terms that can be used in a Terms Query request
1619+
*/
1620+
public int getMaxSourceSizeBytes() {
1621+
return this.maxSourceSizeBytes;
1622+
}
1623+
1624+
private void setMaxSourceSizeBytes(int maxSourceSizeBytes) {
1625+
this.maxSourceSizeBytes = maxSourceSizeBytes;
1626+
}
1627+
16061628
/**
16071629
* Returns the maximum number of terms that can be used in a Terms Query request
16081630
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ public ParsedDocument parseDocument(SourceToParse source, MappingLookup mappingL
7979
if (source.source() != null && source.source().length() == 0) {
8080
throw new DocumentParsingException(new XContentLocation(0, 0), "failed to parse, document is empty");
8181
}
82+
83+
int maxSourceSize = mappingParserContext.getIndexSettings().getMaxSourceSizeBytes();
84+
if (source.source().length() > maxSourceSize) {
85+
throw new DocumentParsingException(
86+
new XContentLocation(0, 0),
87+
"failed to parse, document too large. " + "Max allowed is " + maxSourceSize + " bytes."
88+
);
89+
}
90+
8291
final RootDocumentParserContext context;
8392
final XContentType xContentType = source.getXContentType();
8493

0 commit comments

Comments
 (0)