Skip to content

Commit 6b8b3ef

Browse files
authored
Add strict_allow_templates dynamic mapping option (opensearch-project#14555)
* The dynamic mapping parameter supports strict_allow_templates Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Modify change log Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Modify skip version in yml test file Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Refactor some code Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Keep the old methods Signed-off-by: Gao Binlong <gbinlong@amazon.com> * change public to private Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Optimize some code Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Do not override toString method for Dynamic Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Optimize some code and modify the changelog Signed-off-by: Gao Binlong <gbinlong@amazon.com> --------- Signed-off-by: Gao Binlong <gbinlong@amazon.com>
1 parent 0848525 commit 6b8b3ef

File tree

8 files changed

+688
-57
lines changed

8 files changed

+688
-57
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212
- [Workload Management] Add QueryGroup schema ([13669](https://github.com/opensearch-project/OpenSearch/pull/13669))
1313
- Add batching supported processor base type AbstractBatchingProcessor ([#14554](https://github.com/opensearch-project/OpenSearch/pull/14554))
1414
- Fix race condition while parsing derived fields from search definition ([14445](https://github.com/opensearch-project/OpenSearch/pull/14445))
15+
- Add `strict_allow_templates` dynamic mapping option ([#14555](https://github.com/opensearch-project/OpenSearch/pull/14555))
1516
- Add allowlist setting for ingest-common and search-pipeline-common processors ([#14439](https://github.com/opensearch-project/OpenSearch/issues/14439))
1617
- Create SystemIndexRegistry with helper method matchesSystemIndex ([#14415](https://github.com/opensearch-project/OpenSearch/pull/14415))
1718
- Print reason why parent task was cancelled ([#14604](https://github.com/opensearch-project/OpenSearch/issues/14604))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
"Index documents with setting dynamic parameter to strict_allow_templates in the mapping of the index":
3+
- skip:
4+
version: " - 2.99.99"
5+
reason: "introduced in 3.0.0"
6+
7+
- do:
8+
indices.create:
9+
index: test_1
10+
body:
11+
mappings:
12+
dynamic: strict_allow_templates
13+
dynamic_templates: [
14+
{
15+
strings: {
16+
"match": "stringField*",
17+
"match_mapping_type": "string",
18+
"mapping": {
19+
"type": "keyword"
20+
}
21+
}
22+
},
23+
{
24+
object: {
25+
"match": "objectField*",
26+
"match_mapping_type": "object",
27+
"mapping": {
28+
"type": "object",
29+
"properties": {
30+
"bar1": {
31+
"type": "keyword"
32+
},
33+
"bar2": {
34+
"type": "text"
35+
}
36+
}
37+
}
38+
}
39+
},
40+
{
41+
boolean: {
42+
"match": "booleanField*",
43+
"match_mapping_type": "boolean",
44+
"mapping": {
45+
"type": "boolean"
46+
}
47+
}
48+
},
49+
{
50+
double: {
51+
"match": "doubleField*",
52+
"match_mapping_type": "double",
53+
"mapping": {
54+
"type": "double"
55+
}
56+
}
57+
},
58+
{
59+
long: {
60+
"match": "longField*",
61+
"match_mapping_type": "long",
62+
"mapping": {
63+
"type": "long"
64+
}
65+
}
66+
},
67+
{
68+
array: {
69+
"match": "arrayField*",
70+
"mapping": {
71+
"type": "keyword"
72+
}
73+
}
74+
},
75+
{
76+
date: {
77+
"match": "dateField*",
78+
"match_mapping_type": "date",
79+
"mapping": {
80+
"type": "date"
81+
}
82+
}
83+
}
84+
]
85+
properties:
86+
test1:
87+
type: text
88+
89+
- do:
90+
catch: /mapping set to strict_allow_templates, dynamic introduction of \[test2\] within \[\_doc\] is not allowed/
91+
index:
92+
index: test_1
93+
id: 1
94+
body: {
95+
stringField: bar,
96+
objectField: {
97+
bar1: "bar1",
98+
bar2: "bar2"
99+
},
100+
test1: test1,
101+
test2: test2
102+
}
103+
104+
- do:
105+
index:
106+
index: test_1
107+
id: 1
108+
body: {
109+
stringField: bar,
110+
objectField: {
111+
bar1: "bar1",
112+
bar2: "bar2"
113+
},
114+
booleanField: true,
115+
doubleField: 1.0,
116+
longField: 100,
117+
arrayField: ["1","2"],
118+
dateField: "2024-06-25T05:11:51.243Z",
119+
test1: test1
120+
}
121+
122+
- do:
123+
get:
124+
index: test_1
125+
id: 1
126+
- match: { _source: {
127+
stringField: bar,
128+
objectField: {
129+
bar1: "bar1",
130+
bar2: "bar2"
131+
},
132+
booleanField: true,
133+
doubleField: 1.0,
134+
longField: 100,
135+
arrayField: [ "1","2" ],
136+
dateField: "2024-06-25T05:11:51.243Z",
137+
test1: test1
138+
}
139+
}
140+
141+
- do:
142+
indices.get_mapping: {
143+
index: test_1
144+
}
145+
146+
- match: {test_1.mappings.dynamic: strict_allow_templates}
147+
- match: {test_1.mappings.properties.stringField.type: keyword}
148+
- match: {test_1.mappings.properties.objectField.properties.bar1.type: keyword}
149+
- match: {test_1.mappings.properties.objectField.properties.bar2.type: text}
150+
- match: {test_1.mappings.properties.booleanField.type: boolean}
151+
- match: {test_1.mappings.properties.doubleField.type: double}
152+
- match: {test_1.mappings.properties.longField.type: long}
153+
- match: {test_1.mappings.properties.arrayField.type: keyword}
154+
- match: {test_1.mappings.properties.dateField.type: date}
155+
- match: {test_1.mappings.properties.test1.type: text}

rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/all_path_options.yml

+31
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,34 @@ setup:
159159
indices.get_mapping: {}
160160

161161
- match: {test_index1.mappings.properties.text.type: text}
162+
163+
---
164+
"post a mapping with setting dynamic to strict_allow_templates":
165+
- skip:
166+
version: " - 2.99.99"
167+
reason: "introduced in 3.0.0"
168+
- do:
169+
indices.put_mapping:
170+
index: test_index1
171+
body:
172+
dynamic: strict_allow_templates
173+
dynamic_templates: [
174+
{
175+
strings: {
176+
"match": "foo*",
177+
"match_mapping_type": "string",
178+
"mapping": {
179+
"type": "keyword"
180+
}
181+
}
182+
}
183+
]
184+
properties:
185+
test1:
186+
type: text
187+
188+
- do:
189+
indices.get_mapping: {}
190+
191+
- match: {test_index1.mappings.dynamic: strict_allow_templates}
192+
- match: {test_index1.mappings.properties.test1.type: text}

0 commit comments

Comments
 (0)