Skip to content

Commit 6f301f5

Browse files
committed
Add test for the new control
1 parent d26055a commit 6f301f5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
6868
import org.elasticsearch.common.settings.Settings;
6969
import org.elasticsearch.common.util.concurrent.ThreadContext;
70+
import org.elasticsearch.index.mapper.DocumentParsingException;
7071
import org.elasticsearch.index.query.QueryBuilders;
7172
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
7273
import org.elasticsearch.plugins.NetworkPlugin;
@@ -83,6 +84,8 @@
8384
import org.elasticsearch.transport.TransportInterceptor;
8485
import org.elasticsearch.transport.TransportRequest;
8586
import org.elasticsearch.transport.TransportRequestHandler;
87+
import org.elasticsearch.xcontent.XContentBuilder;
88+
import org.elasticsearch.xcontent.XContentFactory;
8689
import org.junit.After;
8790
import org.junit.Before;
8891

@@ -100,6 +103,7 @@
100103

101104
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
102105
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
106+
import static org.hamcrest.Matchers.containsString;
103107
import static org.hamcrest.Matchers.emptyIterable;
104108
import static org.hamcrest.Matchers.equalTo;
105109
import static org.hamcrest.Matchers.greaterThan;
@@ -582,6 +586,45 @@ public void testSearchDfsQueryThenFetch() throws Exception {
582586
);
583587
}
584588

589+
public void testRejectDocumentWithTooManyArrayObjectFields() throws Exception {
590+
String indexName = "array-limit-test";
591+
int arrayLimit = 10;
592+
593+
assertAcked(
594+
prepareCreate(indexName).setSettings(Settings.builder().put("index.mapping.nested_objects.limit", arrayLimit).build())
595+
.setMapping("""
596+
{
597+
"properties": {
598+
"array": {
599+
"properties": {
600+
"value": { "type": "integer" }
601+
}
602+
}
603+
}
604+
}
605+
""")
606+
);
607+
608+
try (XContentBuilder doc = XContentFactory.jsonBuilder()) {
609+
doc.startObject();
610+
doc.startArray("array");
611+
for (int i = 0; i < arrayLimit + 1; i++) {
612+
doc.startObject();
613+
doc.field("value", i);
614+
doc.endObject();
615+
}
616+
doc.endArray();
617+
doc.endObject();
618+
619+
Exception e = expectThrows(DocumentParsingException.class, () -> { client().prepareIndex(indexName).setSource(doc).get(); });
620+
621+
assertThat(
622+
e.getMessage(),
623+
containsString("The number of nested documents has exceeded " + "the allowed limit of [" + arrayLimit + "]")
624+
);
625+
}
626+
}
627+
585628
private static void assertSameIndices(IndicesRequest originalRequest, String... actions) {
586629
assertSameIndices(originalRequest, false, actions);
587630
}

0 commit comments

Comments
 (0)