| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | [[mapping-source-field]]=== `_source` fieldThe `_source` field contains the original JSON document body that was passedat index time.  The `_source` field itself is not indexed (and thus is notsearchable), but it is stored so that it can be returned when executing_fetch_ requests, like <<docs-get,get>> or <<search-search,search>>.==== Disabling the `_source` fieldThough very handy to have around, the source field does incur storage overheadwithin the index. For this reason, it can be disabled as follows:[source,js]--------------------------------------------------PUT tweets{  "mappings": {    "_source": {      "enabled": false    }  }}--------------------------------------------------// CONSOLE[WARNING].Think before disabling the `_source` field==================================================Users often disable the `_source` field without thinking about theconsequences, and then live to regret it.  If the `_source` field isn'tavailable then a number of features are not supported:* The <<docs-update,`update`>>, <<docs-update-by-query,`update_by_query`>>,and <<docs-reindex,`reindex`>> APIs.* On the fly <<search-request-highlighting,highlighting>>.* The ability to reindex from one Elasticsearch index to another, either  to change mappings or analysis, or to upgrade an index to a new major  version.* The ability to debug queries or aggregations by viewing the original  document used at index time.* Potentially in the future, the ability to repair index corruption  automatically.==================================================TIP: If disk space is a concern, rather increase the<<index-codec,compression level>> instead of disabling the `_source`..The metrics use case**************************************************The _metrics_ use case is distinct from other time-based or logging use casesin that there are many small documents which consist only of numbers, dates,or keywords.  There are no updates, no highlighting requests, and the dataages quickly so there is no need to reindex.  Search requests typically usesimple queries to filter the dataset by date or tags, and the results arereturned as aggregations.In this case, disabling the `_source` field will save space and reduce I/O.**************************************************[[include-exclude]]==== Including / Excluding fields from `_source`An expert-only feature is the ability to prune the contents of the `_source`field after the document has been indexed, but before the `_source` field isstored.WARNING: Removing fields from the `_source` has similar downsides to disabling`_source`, especially the fact that you cannot reindex documents from oneElasticsearch index to another. Consider using<<search-request-source-filtering,source filtering>> instead.The `includes`/`excludes` parameters (which also accept wildcards) can be usedas follows:[source,js]--------------------------------------------------PUT logs{  "mappings": {    "_source": {      "includes": [        "*.count",        "meta.*"      ],      "excludes": [        "meta.description",        "meta.other.*"      ]    }  }}PUT logs/_doc/1{  "requests": {    "count": 10,    "foo": "bar" <1>  },  "meta": {    "name": "Some metric",    "description": "Some metric description", <1>    "other": {      "foo": "one", <1>      "baz": "two" <1>    }  }}GET logs/_search{  "query": {    "match": {      "meta.other.foo": "one" <2>    }  }}--------------------------------------------------// CONSOLE<1> These fields will be removed from the stored `_source` field.<2> We can still search on this field, even though it is not in the stored `_source`.
 |