You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _mappings/index.md
+81-38Lines changed: 81 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,89 @@ While [dynamic mappings](#dynamic-mapping) automatically add new data and fields
21
21
22
22
For example, with explicit mappings, you can ensure that `year` is treated as text and `age` as an integer instead of both being interpreted as integers by dynamic mapping.
23
23
24
+
## Mapping structure and concepts
25
+
26
+
Before learning how to create mappings, it's important to understand how mappings are structured and the key terminology used throughout this documentation.
27
+
28
+
### Mapping structure and example
29
+
30
+
OpenSearch mappings follow a hierarchical JSON structure. The following example demonstrates using `text` and `date` fields with their mapping parameters. Additionally, it contains a nested `director` object with its own properties:
31
+
32
+
```json
33
+
PUT /movies
34
+
{
35
+
"mappings": { // Overall mappings object
36
+
"properties": { // Properties container
37
+
"title": { // Field name
38
+
"type": "text", // Field type
39
+
"analyzer": "standard"// Mapping parameter
40
+
},
41
+
"year": { // Field name
42
+
"type": "date", // Field type
43
+
"format": "yyyy"// Mapping parameter
44
+
},
45
+
"director": { // Field name (object type)
46
+
"type": "object", // Field type
47
+
"properties": { // Properties container for nested fields
48
+
"name": { // Field name (nested)
49
+
"type": "text"// Field type
50
+
}
51
+
}
52
+
}
53
+
}
54
+
}
55
+
}
56
+
```
57
+
{% include copy-curl.html %}
58
+
59
+
### Key terminology
60
+
61
+
-**Mappings**: The overall schema definition for an index.
62
+
-**Properties**: The container for all field definitions within mappings.
63
+
-**Field**: An individual data element (like `title` or `year`).
64
+
-**Field type**: Defines how the field data is stored and indexed (for example, `text`, `integer`, `date`). For more information, see [Supported field types]({{site.url}}{{site.baseurl}}/mappings/supported-field-types/).
65
+
-**Mapping parameters**: Configuration options that modify field behavior (for example, `analyzer`, `coerce`, `format`). For more information, see [Mapping parameters]({{site.url}}{{site.baseurl}}/mappings/mapping-parameters/).
66
+
67
+
## Explicit mapping
68
+
69
+
If you know exactly which field data types you need to use, then you can specify them in your request body when creating your index, as shown in the following example request:
70
+
71
+
```json
72
+
PUT sample-index1
73
+
{
74
+
"mappings": {
75
+
"properties": {
76
+
"year": { "type" : "text" },
77
+
"age": { "type" : "integer" },
78
+
"director":{ "type" : "text" }
79
+
}
80
+
}
81
+
}
82
+
```
83
+
{% include copy-curl.html %}
84
+
85
+
You cannot change the mapping of an existing field; you can only modify the field's mapping parameters.
86
+
{: .note}
87
+
88
+
To add mappings to an existing index or data stream, you can send a request to the `_mapping` endpoint using the `PUT` or `POST` HTTP method, as shown in the following example request:
89
+
90
+
```json
91
+
POST sample-index1/_mapping
92
+
{
93
+
"properties": {
94
+
"year": { "type" : "text" },
95
+
"age": { "type" : "integer" },
96
+
"director":{ "type" : "text" }
97
+
}
98
+
}
99
+
```
100
+
{% include copy-curl.html %}
101
+
102
+
For more information about the Mapping API, see [Update mapping]({{site.url}}{{site.baseurl}}/api-reference/index-apis/put-mapping/).
103
+
24
104
## Dynamic mapping
25
105
26
-
When you index a document, OpenSearch adds fields automatically with dynamic mapping. You can also explicitly add fields to an index mapping.
106
+
When you index a document, OpenSearch can automatically detect and add new fields using dynamic mapping. This behavior differs from using explicit mappings, in which you define field types ahead of time.
27
107
28
108
### Dynamic mapping rules
29
109
@@ -166,43 +246,6 @@ With numeric detection enabled:
166
246
- The `price` field will be mapped as a `float` field
167
247
- The `quantity` field will be mapped as a `long` field
168
248
169
-
## Explicit mapping
170
-
171
-
If you know exactly which field data types you need to use, then you can specify them in your request body when creating your index, as shown in the following example request:
172
-
173
-
```json
174
-
PUT sample-index1
175
-
{
176
-
"mappings": {
177
-
"properties": {
178
-
"year": { "type" : "text" },
179
-
"age": { "type" : "integer" },
180
-
"director":{ "type" : "text" }
181
-
}
182
-
}
183
-
}
184
-
```
185
-
{% include copy-curl.html %}
186
-
187
-
You cannot change the mapping of an existing field, you can only modify the field's mapping parameters.
188
-
{: .note}
189
-
190
-
To add mappings to an existing index or data stream, you can send a request to the `_mapping` endpoint using the `PUT` or `POST` HTTP method, as shown in the following example request:
191
-
192
-
```json
193
-
POST sample-index1/_mapping
194
-
{
195
-
"properties": {
196
-
"year": { "type" : "text" },
197
-
"age": { "type" : "integer" },
198
-
"director":{ "type" : "text" }
199
-
}
200
-
}
201
-
```
202
-
{% include copy-curl.html %}
203
-
204
-
For more information about the Mapping API, see [Update mapping]({{site.url}}{{site.baseurl}}/api-reference/index-apis/put-mapping/).
205
-
206
249
## Retrieving mappings
207
250
208
251
To get all mappings for one or more indexes, use the following request:
0 commit comments