|
67 | 67 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry; |
68 | 68 | import org.elasticsearch.common.settings.Settings; |
69 | 69 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
| 70 | +import org.elasticsearch.index.mapper.DocumentParsingException; |
70 | 71 | import org.elasticsearch.index.query.QueryBuilders; |
71 | 72 | import org.elasticsearch.indices.TestIndexNameExpressionResolver; |
72 | 73 | import org.elasticsearch.plugins.NetworkPlugin; |
|
83 | 84 | import org.elasticsearch.transport.TransportInterceptor; |
84 | 85 | import org.elasticsearch.transport.TransportRequest; |
85 | 86 | import org.elasticsearch.transport.TransportRequestHandler; |
| 87 | +import org.elasticsearch.xcontent.XContentBuilder; |
| 88 | +import org.elasticsearch.xcontent.XContentFactory; |
86 | 89 | import org.junit.After; |
87 | 90 | import org.junit.Before; |
88 | 91 |
|
|
100 | 103 |
|
101 | 104 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
102 | 105 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse; |
| 106 | +import static org.hamcrest.Matchers.containsString; |
103 | 107 | import static org.hamcrest.Matchers.emptyIterable; |
104 | 108 | import static org.hamcrest.Matchers.equalTo; |
105 | 109 | import static org.hamcrest.Matchers.greaterThan; |
@@ -582,6 +586,45 @@ public void testSearchDfsQueryThenFetch() throws Exception { |
582 | 586 | ); |
583 | 587 | } |
584 | 588 |
|
| 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 | + |
585 | 628 | private static void assertSameIndices(IndicesRequest originalRequest, String... actions) { |
586 | 629 | assertSameIndices(originalRequest, false, actions); |
587 | 630 | } |
|
0 commit comments