2015-08-15 12:00:55 -04:00
[[mapper-size]]
=== Mapper Size Plugin
2013-08-28 19:24:34 -04:00
2015-08-15 12:00:55 -04:00
The mapper-size plugin provides the `_size` meta field which, when enabled,
indexes the size in bytes of the original
{ref}/mapping-source-field.html[`_source`] field.
2017-04-20 09:01:37 -04:00
:plugin_name: mapper-size
include::install_remove.asciidoc[]
2015-08-15 12:00:55 -04:00
[[mapper-size-usage]]
==== Using the `_size` field
In order to enable the `_size` field, set the mapping as follows:
2013-08-28 19:24:34 -04:00
[source,js]
2015-07-19 19:24:29 -04:00
--------------------------
2019-01-14 16:08:01 -05:00
PUT my_index?include_type_name=true
2013-08-28 19:24:34 -04:00
{
2015-07-19 19:24:29 -04:00
"mappings": {
2018-10-22 14:54:04 -04:00
"_doc": {
2015-07-19 19:24:29 -04:00
"_size": {
"enabled": true
}
2013-08-28 19:24:34 -04:00
}
2015-07-19 19:24:29 -04:00
}
2013-08-28 19:24:34 -04:00
}
2015-07-19 19:24:29 -04:00
--------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2015-07-19 19:24:29 -04:00
2016-07-01 12:13:29 -04:00
The value of the `_size` field is accessible in queries, aggregations, scripts,
and when sorting:
2015-07-19 19:24:29 -04:00
[source,js]
--------------------------
# Example documents
2018-10-22 14:54:04 -04:00
PUT my_index/_doc/1
2015-07-19 19:24:29 -04:00
{
"text": "This is a document"
}
2018-10-22 14:54:04 -04:00
PUT my_index/_doc/2
2015-07-19 19:24:29 -04:00
{
"text": "This is another document"
}
GET my_index/_search
{
"query": {
"range": {
"_size": { <1>
"gt": 10
}
}
2016-07-01 12:13:29 -04:00
},
"aggs": {
"sizes": {
"terms": {
"field": "_size", <2>
"size": 10
}
}
},
"sort": [
{
"_size": { <3>
"order": "desc"
}
}
],
"script_fields": {
"size": {
"script": "doc['_size']" <4>
}
2015-07-19 19:24:29 -04:00
}
}
--------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2016-05-13 16:15:51 -04:00
// TEST[continued]
2015-07-19 19:24:29 -04:00
<1> Querying on the `_size` field
2016-07-05 09:12:18 -04:00
<2> Aggregating on the `_size` field
<3> Sorting on the `_size` field
<4> Accessing the `_size` field in scripts (inline scripts must be modules-security-scripting.html#enable-dynamic-scripting[enabled] for this example to work)