forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bwc for parsing mappings from dynamic templates (elastic#67763) (e…
…lastic#67969) During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in elastic#66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes elastic#66765
- Loading branch information
Christoph Büscher
authored
Jan 26, 2021
1 parent
3bb6e7d
commit 6439dce
Showing
5 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...nternalClusterTest/java/org/elasticsearch/indices/mapping/MalformedDynamicTemplateIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.indices.mapping; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; | ||
|
||
public class MalformedDynamicTemplateIT extends ESIntegTestCase { | ||
|
||
@Override | ||
protected boolean forbidPrivateIndexSettings() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Check that we can index a document into an 7.x index with a matching dynamic template that | ||
* contains unknown parameters. We were able to create those templates in 7.x still, so we need | ||
* to be able to index new documents into them. Indexing should issue a deprecation warning though. | ||
*/ | ||
public void testBWCMalformedDynamicTemplate() { | ||
String mapping = "{ \"dynamic_templates\": [\n" | ||
+ " {\n" | ||
+ " \"my_template\": {\n" | ||
+ " \"mapping\": {\n" | ||
+ " \"ignore_malformed\": true,\n" // this parameter is not supported by "keyword" field type | ||
+ " \"type\": \"keyword\"\n" | ||
+ " },\n" | ||
+ " \"path_match\": \"*\"\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " }\n" | ||
+ "}}"; | ||
String indexName = "malformed_dynamic_template"; | ||
assertAcked(prepareCreate(indexName).setSettings(Settings.builder().put(indexSettings()) | ||
.put("number_of_shards", 1) | ||
.put("index.version.created", VersionUtils.randomCompatibleVersion(random(), Version.CURRENT)) | ||
).addMapping("_doc", mapping, XContentType.JSON).get()); | ||
client().prepareIndex(indexName, "_doc").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get(); | ||
assertNoFailures((client().admin().indices().prepareRefresh(indexName)).get()); | ||
assertHitCount(client().prepareSearch(indexName).get(), 1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters