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 is 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 source filtering instead.
The includes/excludes parameters (which also accept wildcards) can be used as follows:
PUT logs
{
"mappings": {
"_source": {
"includes": [
"*.count",
"meta.*"
],
"excludes": [
"meta.description",
"meta.other.*"
]
}
}
}
PUT logs/_doc/1
{
"requests": {
"count": 10,
"foo": "bar"
},
"meta": {
"name": "Some metric",
"description": "Some metric description",
"other": {
"foo": "one",
"baz": "two"
}
}
}
GET logs/_search
{
"query": {
"match": {
"meta.other.foo": "one"
}
}
}
These fields will be removed from the stored _source field.
We can still search on this field, even though it is not in the stored _source.