Retrieve stored fields using the Get document API
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Stack
Generally available
You can use the Get API's stored_fields parameter to retrieve fields marked as stored ("store": true) in the index mapping.
Fields not marked as stored are excluded from the response, even if specified in the request.
For example, these PUT requests define a stored field in the mapping and add a document:
PUT my-index-000001{ "mappings": { "properties": { "counter": { "type": "integer", "store": false }, "tags": { "type": "keyword", "store": true } } } }
PUT my-index-000001/_doc/1{ "counter": 1, "tags": [ "production" ] }
This request retrieves the stored fields from the document:
GET my-index-000001/_doc/1?stored_fields=tags,counter
The API returns the following response:
{
"_index": "my-index-000001",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"fields": {
"tags": [
"production"
]
}
}
Although the counter field is specified in the request, it's not included in the response because it's not actually a stored field.
Field values are returned as an array.
Only leaf fields can be retrieved with the stored_fields parameter. If you specify an object field instead, an error is returned.