Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
2.13
Describe the issue :
Creating an index with dynamic set to strict_allow_templates is not working
Configuration :
Configuration same as it is in the documentation. I copied and posted to devtools opensearch and it fails with the following exception
Relevant Logs or Screenshots :
pablo
October 10, 2024, 11:19pm
2
@rajanimaski Your documentation link regards the latest version 2.17.0. According to your post, you’re running version 2.13.0.
strict_allow_templates
value for the dynamic field has been introduced in version 2.16.0.
The error is expected in 2.13.0 as the dynamic field in that version supports only boolean values true and false.
opensearch-project:main
← gaobinlong:template
opened 09:20AM - 26 Jun 24 UTC
### Description
This PR adds a new type `strict_allow_templates` for the `dyn… amic` parameter of the index mappings. If `strict_allow_templates` is used and new detected fields can match the pre-defined dynamic templates in the index mappings, then these fields can be added to the mapping dynamically, if not match, an exception will be thrown: `mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed`(same to `strict` type).
The usage is:
1. Create an index with setting `dynamic` to `strict_allow_templates`
```
PUT index1
{
"mappings": {
"dynamic": "strict_allow_templates",
"dynamic_templates": [
{
"strings": {
"match": "foo*",
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
],
"properties": {
"test1": {
"type": "text"
}
}
}
}
```
2. Field `test1` exists in the explicit mapping, and field `foo` can match the dynamic template, so index the document `1` successes.
```
POST index1/_doc/1
{
"foo": "1",
"test1": "test1"
}
```
3. Field `test2` doesn't exist in the explicit mapping and cannot match the dynamic template, so index the document `2` fails.
```
POST index1/_doc/2
{
"foo": "1",
"test2": "test2"
}
```
throws:
```
{
"error": {
"root_cause": [
{
"type": "strict_dynamic_mapping_exception",
"reason": "mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed"
}
],
"type": "strict_dynamic_mapping_exception",
"reason": "mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed"
},
"status": 400
}
```
### Related Issues
https://github.com/opensearch-project/OpenSearch/issues/11276
### Check List
- [x] Functionality includes testing.
- [ ] API changes companion pull request [created](https://github.com/opensearch-project/opensearch-api-specification/blob/main/DEVELOPER_GUIDE.md), if applicable.
- [ ] Public documentation issue/PR [created](https://github.com/opensearch-project/documentation-website/issues/new/choose), if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).
1 Like