Skip to content

Commit d21ca69

Browse files
committed
update after review
1 parent 1020dff commit d21ca69

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.elasticsearch.common.settings.Settings;
6969
import org.elasticsearch.common.util.concurrent.ThreadContext;
7070
import org.elasticsearch.index.mapper.DocumentParsingException;
71+
import org.elasticsearch.index.mapper.MapperService;
7172
import org.elasticsearch.index.query.QueryBuilders;
7273
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
7374
import org.elasticsearch.plugins.NetworkPlugin;
@@ -590,7 +591,11 @@ public void testRejectDocumentWithTooManyArrayObjectFields() throws Exception {
590591
String indexName = "array-limit-test";
591592
int arrayLimit = 10;
592593

593-
assertAcked(prepareCreate(indexName).setSettings(Settings.builder().put("index.mapping.nested_objects.limit", arrayLimit).build()));
594+
assertAcked(
595+
prepareCreate(indexName).setSettings(
596+
Settings.builder().put(MapperService.INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING.getKey(), arrayLimit).build()
597+
)
598+
);
594599

595600
try (XContentBuilder doc = XContentFactory.jsonBuilder()) {
596601
doc.startObject();
@@ -607,7 +612,7 @@ public void testRejectDocumentWithTooManyArrayObjectFields() throws Exception {
607612

608613
assertThat(
609614
e.getMessage(),
610-
containsString("The number of nested documents has exceeded " + "the allowed limit of [" + arrayLimit + "]")
615+
containsString("The number of array objects has exceeded " + "the allowed limit of [" + arrayLimit + "]")
611616
);
612617
}
613618
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
167167
Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING,
168168
MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING,
169169
MapperService.INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING,
170+
MapperService.INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING,
170171
MapperService.INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_LIMIT_SETTING,
171172
MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING,
172173
MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_VERSION_CREATED;
5050
import static org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING;
51+
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING;
5152
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING;
5253
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_DIMENSION_FIELDS_LIMIT_SETTING;
5354
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_FIELD_NAME_LENGTH_LIMIT_SETTING;
@@ -925,6 +926,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
925926
private volatile String requiredPipeline;
926927
private volatile long mappingNestedFieldsLimit;
927928
private volatile long mappingNestedDocsLimit;
929+
private volatile long mappingArrayObjectsLimit;
928930
private volatile long mappingTotalFieldsLimit;
929931
private volatile boolean ignoreDynamicFieldsBeyondLimit;
930932
private volatile long mappingDepthLimit;
@@ -1100,6 +1102,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
11001102
defaultPipeline = scopedSettings.get(DEFAULT_PIPELINE);
11011103
mappingNestedFieldsLimit = scopedSettings.get(INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING);
11021104
mappingNestedDocsLimit = scopedSettings.get(INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING);
1105+
mappingArrayObjectsLimit = scopedSettings.get(INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING);
11031106
mappingTotalFieldsLimit = scopedSettings.get(INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING);
11041107
ignoreDynamicFieldsBeyondLimit = scopedSettings.get(INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_LIMIT_SETTING);
11051108
mappingDepthLimit = scopedSettings.get(INDEX_MAPPING_DEPTH_LIMIT_SETTING);
@@ -1215,6 +1218,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
12151218
scopedSettings.addSettingsUpdateConsumer(INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING, this::setRetentionLeaseMillis);
12161219
scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING, this::setMappingNestedFieldsLimit);
12171220
scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING, this::setMappingNestedDocsLimit);
1221+
scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING, this::setMappingArrayObjectsLimit);
12181222
scopedSettings.addSettingsUpdateConsumer(
12191223
INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_LIMIT_SETTING,
12201224
this::setIgnoreDynamicFieldsBeyondLimit
@@ -1754,6 +1758,14 @@ private void setMappingNestedDocsLimit(long value) {
17541758
this.mappingNestedDocsLimit = value;
17551759
}
17561760

1761+
public long getMappingArrayObjectsLimit() {
1762+
return mappingArrayObjectsLimit;
1763+
}
1764+
1765+
private void setMappingArrayObjectsLimit(long value) {
1766+
this.mappingArrayObjectsLimit = value;
1767+
}
1768+
17571769
public long getMappingTotalFieldsLimit() {
17581770
return mappingTotalFieldsLimit;
17591771
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,16 +750,16 @@ private static void parseNonDynamicArray(
750750
XContentParser.Token previousToken = parser.currentToken();
751751
int elements = 0;
752752
int countArray = 0;
753-
long nestedDocsLimit = context.indexSettings().getMappingNestedDocsLimit();
753+
long arrayObjectsLimit = context.indexSettings().getMappingArrayObjectsLimit();
754754
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
755755
if (token == XContentParser.Token.START_OBJECT) {
756-
if (countArray++ >= nestedDocsLimit) {
756+
if (countArray++ >= arrayObjectsLimit) {
757757
throw new IllegalStateException(
758-
"The number of nested documents has exceeded the allowed limit of ["
759-
+ nestedDocsLimit
758+
"The number of array objects has exceeded the allowed limit of ["
759+
+ arrayObjectsLimit
760760
+ "]. "
761761
+ "This limit can be set by changing the ["
762-
+ MapperService.INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING.getKey()
762+
+ MapperService.INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING.getKey()
763763
+ "] index level setting."
764764
);
765765
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public boolean isAutoUpdate() {
116116
Property.Dynamic,
117117
Property.IndexScope
118118
);
119+
// maximum allowed number of objects for an array field in a document
120+
public static final Setting<Long> INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING = Setting.longSetting(
121+
"index.mapping.array_objects.limit",
122+
20000L,
123+
0,
124+
Property.Dynamic,
125+
Property.IndexScope
126+
);
127+
119128
public static final Setting<Long> INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING = Setting.longSetting(
120129
"index.mapping.total_fields.limit",
121130
1000L,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public void testLimitNestedDocs() throws Exception {
905905
SourceToParse source2 = new SourceToParse("2", BytesReference.bytes(docBuilder2), XContentType.JSON);
906906
DocumentParsingException e = expectThrows(DocumentParsingException.class, () -> docMapper.parse(source2));
907907
assertEquals(
908-
"[1:73] failed to parse: The number of nested documents has exceeded the allowed limit of ["
908+
"[1:73] The number of nested documents has exceeded the allowed limit of ["
909909
+ maxNoNestedDocs
910910
+ "]. This limit can be set by changing the ["
911911
+ MapperService.INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING.getKey()

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
@@ -322,6 +322,7 @@ public void testDynamicIndexSettingsAreClassified() {
322322
replicatedSettings.add(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING);
323323
replicatedSettings.add(MapperService.INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_LIMIT_SETTING);
324324
replicatedSettings.add(MapperService.INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING);
325+
replicatedSettings.add(MapperService.INDEX_MAPPING_ARRAY_OBJECTS_LIMIT_SETTING);
325326
replicatedSettings.add(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING);
326327
replicatedSettings.add(MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING);
327328
replicatedSettings.add(MapperService.INDEX_MAPPING_FIELD_NAME_LENGTH_LIMIT_SETTING);

0 commit comments

Comments
 (0)