2013-08-28 19:24:34 -04:00
|
|
|
[[mapping-source-field]]
|
2015-07-19 19:24:29 -04:00
|
|
|
=== `_source` field
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-07-19 19:24:29 -04:00
|
|
|
The `_source` field contains the original JSON document body that was passed
|
|
|
|
at index time. The `_source` field itself is not indexed (and thus is not
|
|
|
|
searchable), but it is stored so that it can be returned when executing
|
|
|
|
_fetch_ requests, like <<docs-get,get>> or <<search-search,search>>.
|
2015-07-10 09:49:20 -04:00
|
|
|
|
2019-04-30 10:19:09 -04:00
|
|
|
[[disable-source-field]]
|
2015-07-19 19:24:29 -04:00
|
|
|
==== Disabling the `_source` field
|
2015-07-10 09:49:20 -04:00
|
|
|
|
|
|
|
Though very handy to have around, the source field does incur storage overhead
|
|
|
|
within the index. For this reason, it can be disabled as follows:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-07-10 09:49:20 -04:00
|
|
|
--------------------------------------------------
|
2020-08-03 13:31:19 -04:00
|
|
|
PUT my-index-000001
|
2015-07-10 09:49:20 -04:00
|
|
|
{
|
2015-09-11 10:34:14 -04:00
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"_source": {
|
|
|
|
"enabled": false
|
2015-07-10 09:49:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[WARNING]
|
2015-07-19 19:24:29 -04:00
|
|
|
.Think before disabling the `_source` field
|
2015-07-10 09:49:20 -04:00
|
|
|
==================================================
|
|
|
|
|
|
|
|
Users often disable the `_source` field without thinking about the
|
|
|
|
consequences, and then live to regret it. If the `_source` field isn't
|
|
|
|
available then a number of features are not supported:
|
|
|
|
|
2016-04-11 19:05:09 -04:00
|
|
|
* The <<docs-update,`update`>>, <<docs-update-by-query,`update_by_query`>>,
|
|
|
|
and <<docs-reindex,`reindex`>> APIs.
|
2015-07-10 09:49:20 -04:00
|
|
|
|
2020-07-17 10:57:00 -04:00
|
|
|
* On the fly <<highlighting,highlighting>>.
|
2015-07-10 09:49:20 -04:00
|
|
|
|
|
|
|
* 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.
|
2015-07-19 19:24:29 -04:00
|
|
|
==================================================
|
2015-07-10 09:49:20 -04:00
|
|
|
|
2015-07-19 19:24:29 -04:00
|
|
|
TIP: If disk space is a concern, rather increase the
|
2015-07-10 09:49:20 -04:00
|
|
|
<<index-codec,compression level>> instead of disabling the `_source`.
|
|
|
|
|
|
|
|
[[include-exclude]]
|
2015-07-19 19:24:29 -04:00
|
|
|
==== Including / Excluding fields from `_source`
|
2015-07-10 09:49:20 -04:00
|
|
|
|
|
|
|
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 is
|
2015-07-19 19:24:29 -04:00
|
|
|
stored.
|
|
|
|
|
|
|
|
WARNING: Removing fields from the `_source` has similar downsides to disabling
|
|
|
|
`_source`, especially the fact that you cannot reindex documents from one
|
|
|
|
Elasticsearch index to another. Consider using
|
2020-06-11 11:25:04 -04:00
|
|
|
<<source-filtering,source filtering>> instead.
|
2015-07-19 19:24:29 -04:00
|
|
|
|
|
|
|
The `includes`/`excludes` parameters (which also accept wildcards) can be used
|
|
|
|
as follows:
|
2015-07-10 09:49:20 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-07-10 09:49:20 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT logs
|
2015-07-10 09:49:20 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"_source": {
|
|
|
|
"includes": [
|
|
|
|
"*.count",
|
|
|
|
"meta.*"
|
|
|
|
],
|
|
|
|
"excludes": [
|
|
|
|
"meta.description",
|
|
|
|
"meta.other.*"
|
|
|
|
]
|
2015-07-10 09:49:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT logs/_doc/1
|
2015-07-10 09:49:20 -04:00
|
|
|
{
|
|
|
|
"requests": {
|
|
|
|
"count": 10,
|
|
|
|
"foo": "bar" <1>
|
|
|
|
},
|
|
|
|
"meta": {
|
|
|
|
"name": "Some metric",
|
|
|
|
"description": "Some metric description", <1>
|
|
|
|
"other": {
|
|
|
|
"foo": "one", <1>
|
|
|
|
"baz": "two" <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
GET logs/_search
|
2015-07-10 09:49:20 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"meta.other.foo": "one" <2>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
<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`.
|