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: docs/reference/elasticsearch/rest-apis/retrieve-selected-fields.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ By default, each hit in the search response includes the document [`_source`](/r
17
17
You can use both of these methods, though the `fields` option is preferred because it consults both the document data and index mappings. In some instances, you might want to use [other methods](#field-retrieval-methods) of retrieving data.
18
18
19
19
20
-
###The `fields` option [search-fields-param]
20
+
## The `fields` option [search-fields-param]
21
21
22
22
To retrieve specific fields in the search response, use the `fields` parameter. Because it consults the index mappings, the `fields` parameter provides several advantages over referencing the `_source` directly. Specifically, the `fields` parameter:
23
23
@@ -33,7 +33,7 @@ Other mapping options are also respected, including [`ignore_above`](/reference/
33
33
The `fields` option returns values in the way that matches how {{es}} indexes them. For standard fields, this means that the `fields` option looks in `_source` to find the values, then parses and formats them using the mappings. Selected fields that can’t be found in `_source` are skipped.
34
34
35
35
36
-
####Retrieve specific fields [search-fields-request]
36
+
### Retrieve specific fields [search-fields-request]
37
37
38
38
The following search request uses the `fields` parameter to retrieve values for the `user.id` field, all fields starting with `http.response.`, and the `@timestamp` field.
39
39
@@ -69,7 +69,7 @@ By default, document metadata fields like `_id` or `_index` are not returned whe
69
69
70
70
71
71
72
-
####Response always returns an array [search-fields-response]
72
+
### Response always returns an array [search-fields-response]
73
73
74
74
The `fields` response always returns an array of values for each field, even when there is a single value in the `_source`. This is because {{es}} has no dedicated array type, and any field could contain multiple values. The `fields` parameter also does not guarantee that array values are returned in a specific order. See the mapping documentation on [arrays](/reference/elasticsearch/mapping-reference/array.md) for more background.
75
75
@@ -109,7 +109,7 @@ The response includes values as a flat list in the `fields` section for each hit
109
109
```
110
110
111
111
112
-
####Retrieve nested fields [search-fields-nested]
112
+
### Retrieve nested fields [search-fields-nested]
113
113
114
114
::::{dropdown}
115
115
The `fields` response for [`nested` fields](/reference/elasticsearch/mapping-reference/nested.md) is slightly different from that of regular object fields. While leaf values inside regular `object` fields are returned as a flat list, values inside `nested` fields are grouped to maintain the independence of each object inside the original nested array. For each entry inside a nested field array, values are again returned as a flat list unless there are other `nested` fields inside the parent nested object, in which case the same procedure is repeated again for the deeper nested fields.
@@ -246,7 +246,7 @@ However, when the `fields` pattern targets the nested `user` field directly, no
By default, the `fields` parameter returns only values of mapped fields. However, {{es}} allows storing fields in `_source` that are unmapped, such as setting [dynamic field mapping](docs-content://manage-data/data-store/mapping/dynamic-field-mapping.md) to `false` or by using an object field with `enabled: false`. These options disable parsing and indexing of the object content.
@@ -326,7 +326,7 @@ The response will contain field results under the `session_data.object.*` path,
326
326
327
327
328
328
329
-
####Ignored field values [ignored-field-values]
329
+
### Ignored field values [ignored-field-values]
330
330
331
331
::::{dropdown}
332
332
The `fields` section of the response only returns values that were valid when indexed. If your search request asks for values from a field that ignored certain values because they were malformed or too large these values are returned separately in an `ignored_field_values` section.
@@ -578,6 +578,7 @@ Also only leaf fields can be returned via the `stored_fields` option. If an obje
578
578
On its own, `stored_fields` cannot be used to load fields in nested objects — if a field contains a nested object in its path, then no data will be returned for that stored field. To access nested fields, `stored_fields` must be used within an [`inner_hits`](/reference/elasticsearch/rest-apis/retrieve-inner-hits.md) block.
579
579
::::
580
580
581
+
For an example that uses the `stored_fields` parameter, refer to [](retrieve-stored-fields.md).
# Retrieve stored fields using the Get document API [get-stored-fields]
10
+
11
+
Use the `stored_fields` query parameter in a [Get document](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-get) API request to retrieve fields marked as stored (`"store": true`) in the index mapping.
12
+
13
+
Fields not marked as stored are excluded from the response, even if specified in the request.
14
+
15
+
::::{tip}
16
+
In most cases, the [`fields`](retrieve-selected-fields.md#search-fields-param) and [`_source`](retrieve-selected-fields.md#source-filtering) parameters produce better results than `stored_fields`.
17
+
::::
18
+
19
+
For example, these PUT requests define a stored field in the mapping and add a document:
20
+
21
+
```console
22
+
PUT my-index-000001
23
+
{
24
+
"mappings": {
25
+
"properties": {
26
+
"counter": {
27
+
"type": "integer",
28
+
"store": false
29
+
},
30
+
"tags": {
31
+
"type": "keyword",
32
+
"store": true
33
+
}
34
+
}
35
+
}
36
+
}
37
+
```
38
+
39
+
```console
40
+
PUT my-index-000001/_doc/1
41
+
{
42
+
"counter": 1,
43
+
"tags": [ "production" ]
44
+
}
45
+
```
46
+
47
+
% TEST[continued]
48
+
49
+
This request retrieves the stored fields from the document:
50
+
51
+
```console
52
+
GET my-index-000001/_doc/1?stored_fields=tags,counter
0 commit comments