2015-08-15 12:00:55 -04:00
|
|
|
[[mapper-size]]
|
|
|
|
=== Mapper Size Plugin
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-08-05 14:04:55 -04:00
|
|
|
The mapper-size plugin provides the `_size` metadata field which, when enabled,
|
2015-08-15 12:00:55 -04:00
|
|
|
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
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2015-07-19 19:24:29 -04:00
|
|
|
--------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2015-07-19 19:24:29 -04:00
|
|
|
"mappings": {
|
2019-01-18 08:11:18 -05: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-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
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2015-07-19 19:24:29 -04:00
|
|
|
--------------------------
|
|
|
|
# Example documents
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-07-19 19:24:29 -04:00
|
|
|
{
|
|
|
|
"text": "This is a document"
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/2
|
2015-07-19 19:24:29 -04:00
|
|
|
{
|
|
|
|
"text": "This is another document"
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-07-19 19:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"range": {
|
2020-05-28 09:26:49 -04:00
|
|
|
"_size": { <1>
|
2015-07-19 19:24:29 -04:00
|
|
|
"gt": 10
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 12:13:29 -04:00
|
|
|
},
|
|
|
|
"aggs": {
|
|
|
|
"sizes": {
|
|
|
|
"terms": {
|
2020-05-28 09:26:49 -04:00
|
|
|
"field": "_size", <2>
|
2016-07-01 12:13:29 -04:00
|
|
|
"size": 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sort": [
|
|
|
|
{
|
2020-05-28 09:26:49 -04:00
|
|
|
"_size": { <3>
|
2016-07-01 12:13:29 -04:00
|
|
|
"order": "desc"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"script_fields": {
|
|
|
|
"size": {
|
2020-05-28 09:26:49 -04:00
|
|
|
"script": "doc['_size']" <4>
|
2016-07-01 12:13:29 -04:00
|
|
|
}
|
2020-05-28 09:26:49 -04:00
|
|
|
},
|
|
|
|
"docvalue_fields": [
|
|
|
|
{
|
|
|
|
"field": "_size" <5>
|
|
|
|
}
|
|
|
|
]
|
2015-07-19 19:24:29 -04:00
|
|
|
}
|
|
|
|
--------------------------
|
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
|
2020-05-28 09:26:49 -04:00
|
|
|
<4> Uses a
|
2020-08-06 13:06:06 -04:00
|
|
|
{ref}/search-fields.html#script-fields[script field]
|
2020-05-28 09:26:49 -04:00
|
|
|
to return the `_size` field in the search response.
|
|
|
|
<5> Uses a
|
2020-08-06 13:06:06 -04:00
|
|
|
{ref}/search-fields.html#docvalue-fields[doc value
|
2020-05-28 09:26:49 -04:00
|
|
|
field] to return the `_size` field in the search response. Doc value fields are
|
|
|
|
useful if
|
|
|
|
{ref}/modules-scripting-security.html#allowed-script-types-setting[inline
|
|
|
|
scripts are disabled].
|