@@ -168,7 +168,93 @@ no dedicated array type, and any field could contain multiple values. The
168
168
a specific order. See the mapping documentation on <<array, arrays>> for more
169
169
background.
170
170
171
+ [discrete]
172
+ [[retrieve-unmapped-fields]]
173
+ ==== Retrieving unmapped fields
174
+
175
+ By default, the `fields` parameter returns only values of mapped fields. However,
176
+ Elasticsearch allows storing fields in `_source` that are unmapped, for example by
177
+ setting <<dynamic-field-mapping,Dynamic field mapping>> to `false` or by using an
178
+ object field with `enabled: false`, thereby disabling parsing and indexing of its content.
171
179
180
+ Fields in such an object can be retrieved from `_source` using the `include_unmapped` option
181
+ in the `fields` section:
182
+
183
+ [source,console]
184
+ ----
185
+ PUT my-index-000001
186
+ {
187
+ "mappings": {
188
+ "enabled": false <1>
189
+ }
190
+ }
191
+
192
+ PUT my-index-000001/_doc/1?refresh=true
193
+ {
194
+ "user_id": "kimchy",
195
+ "session_data": {
196
+ "object": {
197
+ "some_field": "some_value"
198
+ }
199
+ }
200
+ }
201
+
202
+ POST my-index-000001/_search
203
+ {
204
+ "fields": [
205
+ "user_id",
206
+ {
207
+ "field": "session_data.object.*",
208
+ "include_unmapped" : true <2>
209
+ }
210
+ ],
211
+ "_source": false
212
+ }
213
+ ----
214
+
215
+ <1> Disable all mappings.
216
+ <2> Include unmapped fields matching this field pattern.
217
+
218
+ The response will contain fields results under the `session_data.object.*` path even if the
219
+ fields are unmapped, but will not contain `user_id` since it is unmapped but the `include_unmapped`
220
+ flag hasn't been set to `true` for that field pattern.
221
+
222
+ [source,console-result]
223
+ ----
224
+ {
225
+ "took" : 2,
226
+ "timed_out" : false,
227
+ "_shards" : {
228
+ "total" : 1,
229
+ "successful" : 1,
230
+ "skipped" : 0,
231
+ "failed" : 0
232
+ },
233
+ "hits" : {
234
+ "total" : {
235
+ "value" : 1,
236
+ "relation" : "eq"
237
+ },
238
+ "max_score" : 1.0,
239
+ "hits" : [
240
+ {
241
+ "_index" : "my-index-000001",
242
+ "_id" : "1",
243
+ "_score" : 1.0,
244
+ "_type" : "_doc",
245
+ "fields" : {
246
+ "session_data.object.some_field": [
247
+ "some_value"
248
+ ]
249
+ }
250
+ }
251
+ ]
252
+ }
253
+ }
254
+ ----
255
+ // TESTRESPONSE[s/"took" : 2/"took": $body.took/]
256
+ // TESTRESPONSE[s/"max_score" : 1.0/"max_score" : $body.hits.max_score/]
257
+ // TESTRESPONSE[s/"_score" : 1.0/"_score" : $body.hits.hits.0._score/]
172
258
173
259
[discrete]
174
260
[[docvalue-fields]]
0 commit comments