|
9 | 9 |
|
10 | 10 | package org.elasticsearch.lucene; |
11 | 11 |
|
| 12 | +import org.apache.http.entity.ContentType; |
| 13 | +import org.apache.http.entity.InputStreamEntity; |
12 | 14 | import org.elasticsearch.client.Request; |
13 | 15 | import org.elasticsearch.common.settings.Settings; |
14 | 16 | import org.elasticsearch.core.Strings; |
| 17 | +import org.elasticsearch.index.IndexSettings; |
| 18 | +import org.elasticsearch.index.mapper.MapperService; |
| 19 | +import org.elasticsearch.test.XContentTestUtils; |
15 | 20 | import org.elasticsearch.test.cluster.ElasticsearchCluster; |
16 | 21 | import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider; |
17 | 22 | import org.elasticsearch.test.cluster.local.distribution.DistributionType; |
18 | 23 | import org.elasticsearch.test.cluster.util.Version; |
19 | 24 | import org.elasticsearch.test.rest.ESRestTestCase; |
| 25 | +import org.elasticsearch.xcontent.XContentType; |
20 | 26 | import org.junit.After; |
21 | 27 | import org.junit.Before; |
22 | 28 | import org.junit.ClassRule; |
@@ -153,9 +159,9 @@ protected static void indexDocs(String indexName, int numDocs) throws Exception |
153 | 159 | var request = new Request("POST", "/_bulk"); |
154 | 160 | var docs = new StringBuilder(); |
155 | 161 | IntStream.range(0, numDocs).forEach(n -> docs.append(Strings.format(""" |
156 | | - {"index":{"_id":"%s","_index":"%s"}} |
157 | | - {"test":"test"} |
158 | | - """, n, indexName))); |
| 162 | + {"index":{"_index":"%s"}} |
| 163 | + {"field_0":"%s","field_1":%d,"field_2":"%s"} |
| 164 | + """, indexName, Integer.toString(n), n, randomFrom(Locale.getAvailableLocales()).getDisplayName()))); |
159 | 165 | request.setJsonEntity(docs.toString()); |
160 | 166 | var response = assertOK(client().performRequest(request)); |
161 | 167 | assertThat(entityAsMap(response).get("errors"), allOf(notNullValue(), is(false))); |
@@ -192,4 +198,38 @@ protected static void restoreIndex(String repository, String snapshot, String in |
192 | 198 | assertThat(responseBody.evaluate("snapshot.shards.total"), equalTo((int) responseBody.evaluate("snapshot.shards.failed"))); |
193 | 199 | assertThat(responseBody.evaluate("snapshot.shards.successful"), equalTo(0)); |
194 | 200 | } |
| 201 | + |
| 202 | + protected static void updateRandomIndexSettings(String indexName) throws IOException { |
| 203 | + final var settings = Settings.builder(); |
| 204 | + int updates = randomIntBetween(1, 3); |
| 205 | + for (int i = 0; i < updates; i++) { |
| 206 | + switch (i) { |
| 207 | + case 0 -> settings.putList(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), "field_" + randomInt(2)); |
| 208 | + case 1 -> settings.put(IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey(), randomIntBetween(1, 100)); |
| 209 | + case 2 -> settings.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), randomLongBetween(0L, 1000L)); |
| 210 | + case 3 -> settings.put(IndexSettings.MAX_SLICES_PER_SCROLL.getKey(), randomIntBetween(1, 1024)); |
| 211 | + default -> throw new IllegalStateException(); |
| 212 | + } |
| 213 | + } |
| 214 | + updateIndexSettings(indexName, settings); |
| 215 | + } |
| 216 | + |
| 217 | + protected static void updateRandomMappings(String indexName) throws IOException { |
| 218 | + final var runtime = new HashMap<>(); |
| 219 | + runtime.put("field_" + randomInt(2), Map.of("type", "keyword")); |
| 220 | + final var properties = new HashMap<>(); |
| 221 | + properties.put(randomIdentifier(), Map.of("type", "long")); |
| 222 | + var body = XContentTestUtils.convertToXContent(Map.of("runtime", runtime, "properties", properties), XContentType.JSON); |
| 223 | + var request = new Request("PUT", indexName + "/_mappings"); |
| 224 | + request.setEntity( |
| 225 | + new InputStreamEntity( |
| 226 | + body.streamInput(), |
| 227 | + body.length(), |
| 228 | + |
| 229 | + ContentType.create(XContentType.JSON.mediaTypeWithoutParameters()) |
| 230 | + ) |
| 231 | + ); |
| 232 | + assertOK(client().performRequest(request)); |
| 233 | + } |
| 234 | + |
195 | 235 | } |
0 commit comments