Skip to content

Commit 7113b8c

Browse files
Add documentation for false_allow_templates
Signed-off-by: Bruce Hong <bruce.hong@glean.com>
1 parent 2673a84 commit 7113b8c

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

_field-types/mapping-parameters/dynamic.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,72 @@ PUT testindex1/_doc/1
344344
"floor": "1"
345345
}
346346
```
347+
348+
---
349+
350+
## Example: Create an index with `dynamic` set to `false_allow_templates`
351+
352+
1. Create an index with predefined dynamic templates and `dynamic` set to `false_allow_templates` by sending the following request:
353+
354+
```json
355+
PUT testindex1
356+
{
357+
"mappings": {
358+
"dynamic": "false_allow_templates",
359+
"dynamic_templates": [
360+
{
361+
"strings": {
362+
"match": "room*",
363+
"match_mapping_type": "string",
364+
"mapping": {
365+
"type": "keyword"
366+
}
367+
}
368+
}
369+
],
370+
"properties": {
371+
"patient": {
372+
"properties": {
373+
"id": {
374+
"type": "keyword"
375+
},
376+
"name": {
377+
"type": "keyword"
378+
}
379+
}
380+
}
381+
}
382+
}
383+
}
384+
```
385+
{% include copy-curl.html %}
386+
387+
2. Index a document with an object field `patient` containing two string fields and a new field `room` that matches one of the dynamic templates by sending the following request:
388+
389+
```json
390+
PUT testindex1/_doc/1
391+
{
392+
"patient": {
393+
"name" : "John Doe",
394+
"id" : "123456"
395+
},
396+
"room": "room1"
397+
}
398+
```
399+
{% include copy-curl.html %}
400+
401+
Indexing succeeds because the new field `room` matches the dynamic templates.
402+
403+
3. Indexing also succeeds when the new field `floor` is added even though it does not match any properties or dynamic tamplates. However mappings will not be created for `floor` and so queries such as `{"match": {"floor": "1"}}` will not return the doc.
404+
405+
```json
406+
PUT testindex1/_doc/1
407+
{
408+
"patient": {
409+
"name" : "John Doe",
410+
"id" : "123456"
411+
},
412+
"room": "room1",
413+
"floor": "1"
414+
}
415+
```

_field-types/supported-field-types/nested.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ The following table lists the parameters accepted by object field types. All par
310310

311311
Parameter | Description
312312
:--- | :---
313-
[`dynamic`]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/object#the-dynamic-parameter) | Specifies whether new fields can be dynamically added to the object. Valid values are `true`, `false`, `strict`, and `strict_allow_templates`. Default is `true`.
313+
[`dynamic`]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/object#the-dynamic-parameter) | Specifies whether new fields can be dynamically added to the object. Valid values are `true`, `false`, `strict`, `strict_allow_templates`, and `false_allow_templates`. Default is `true`.
314314
`include_in_parent` | A Boolean value that specifies whether all fields in the child nested object should also be added to the parent document in flattened form. Default is `false`.
315315
`include_in_root` | A Boolean value that specifies whether all fields in the child nested object should also be added to the root document in flattened form. Default is `false`.
316316
`properties` | Fields of this object, which can be of any supported type. New properties can be dynamically added to this object if `dynamic` is set to `true`.

_field-types/supported-field-types/object.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The following table lists the parameters accepted by object field types. All par
7575

7676
Parameter | Description
7777
:--- | :---
78-
[`dynamic`](#the-dynamic-parameter) | Specifies whether new fields can be dynamically added to the object. Valid values are `true`, `false`, `strict`, and `strict_allow_templates`. Default is `true`.
78+
[`dynamic`](#the-dynamic-parameter) | Specifies whether new fields can be dynamically added to the object. Valid values are `true`, `false`, `strict`, `strict_allow_templates`, and `false_allow_templates`. Default is `true`.
7979
`enabled` | A Boolean value that specifies whether the JSON contents of the object should be parsed. If `enabled` is set to `false`, the object's contents are not indexed or searchable, but they are still retrievable from the _source field. Default is `true`.
8080
`properties` | Fields of this object, which can be of any supported type. New properties can be dynamically added to this object if `dynamic` is set to `true`.
8181

@@ -152,6 +152,7 @@ Value | Description
152152
`false` | New fields cannot be added to the mapping dynamically. If a new field is detected, it is not indexed or searchable. However, it is still retrievable from the _source field.
153153
`strict` | When new fields are added to the mapping dynamically, an exception is thrown. To add a new field to an object, you have to add it to the mapping first.
154154
`strict_allow_templates` | If the newly detected fields match any of the predefined dynamic templates in the mapping, then they are added to the mapping; if they do not match any of them, then an exception is thrown.
155+
`false_allow_templates` | If the newly detected fields match any of the predefined dynamic templates in the mapping, then they are added to the mapping; only fields matching dynamic templates or properties are indexed.
155156

156157
Inner objects inherit the `dynamic` parameter value from their parent unless they declare their own `dynamic` parameter value.
157158
{: .note }

0 commit comments

Comments
 (0)