|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.elasticsearch.upgrades; |
| 20 | + |
| 21 | +import org.elasticsearch.Version; |
| 22 | +import org.elasticsearch.client.Request; |
| 23 | +import org.elasticsearch.client.Response; |
| 24 | +import org.elasticsearch.common.xcontent.support.XContentMapValues; |
| 25 | + |
| 26 | +public class MappingIT extends AbstractRollingTestCase { |
| 27 | + /** |
| 28 | + * Create a mapping that explicitly disables the _all field (possible in 6x, see #37429) |
| 29 | + * and check that it can be upgraded to 7x. |
| 30 | + */ |
| 31 | + public void testAllFieldDisable6x() throws Exception { |
| 32 | + assumeTrue("_all", UPGRADE_FROM_VERSION.before(Version.V_7_0_0)); |
| 33 | + switch (CLUSTER_TYPE) { |
| 34 | + case OLD: |
| 35 | + Request createTestIndex = new Request("PUT", "all-index"); |
| 36 | + createTestIndex.addParameter("include_type_name", "false"); |
| 37 | + createTestIndex.setJsonEntity( |
| 38 | + "{ \"settings\": { \"index.number_of_shards\": 1 }, " + |
| 39 | + "\"mappings\": {\"_all\": { \"enabled\": false }, \"properties\": { \"field\": { \"type\": \"text\" }}}}" |
| 40 | + ); |
| 41 | + createTestIndex.setOptions(expectWarnings("[_all] is deprecated in 6.0+ and will be removed in 7.0. As a replacement," + |
| 42 | + " " + "you can use [copy_to] on mapping fields to create your own catch all field.")); |
| 43 | + Response resp = client().performRequest(createTestIndex); |
| 44 | + assertEquals(200, resp.getStatusLine().getStatusCode()); |
| 45 | + break; |
| 46 | + |
| 47 | + default: |
| 48 | + final Request request = new Request("GET", "all-index"); |
| 49 | + Response response = client().performRequest(request); |
| 50 | + assertEquals(200, response.getStatusLine().getStatusCode()); |
| 51 | + Object enabled = XContentMapValues.extractValue("all-index.mappings._all.enabled", entityAsMap(response)); |
| 52 | + assertNotNull(enabled); |
| 53 | + assertEquals(false, enabled); |
| 54 | + break; |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments