2015-08-16 00:00:55 +08:00
|
|
|
[[mapper-size]]
|
|
|
|
=== Mapper Size Plugin
|
2013-08-29 07:24:34 +08:00
|
|
|
|
2020-08-06 01:21:00 +08:00
|
|
|
The mapper-size plugin provides the `_size` metadata field which, when enabled,
|
2015-08-16 00:00:55 +08:00
|
|
|
indexes the size in bytes of the original
|
|
|
|
{ref}/mapping-source-field.html[`_source`] field.
|
|
|
|
|
2017-04-20 21:01:37 +08:00
|
|
|
:plugin_name: mapper-size
|
|
|
|
include::install_remove.asciidoc[]
|
2015-08-16 00:00:55 +08:00
|
|
|
|
|
|
|
[[mapper-size-usage]]
|
|
|
|
==== Using the `_size` field
|
|
|
|
|
|
|
|
In order to enable the `_size` field, set the mapping as follows:
|
2013-08-29 07:24:34 +08:00
|
|
|
|
2019-09-10 01:13:41 +08:00
|
|
|
[source,console]
|
2015-07-20 07:24:29 +08:00
|
|
|
--------------------------
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001
|
2013-08-29 07:24:34 +08:00
|
|
|
{
|
2015-07-20 07:24:29 +08:00
|
|
|
"mappings": {
|
2019-01-18 21:11:18 +08:00
|
|
|
"_size": {
|
|
|
|
"enabled": true
|
2013-08-29 07:24:34 +08:00
|
|
|
}
|
2015-07-20 07:24:29 +08:00
|
|
|
}
|
2013-08-29 07:24:34 +08:00
|
|
|
}
|
2015-07-20 07:24:29 +08:00
|
|
|
--------------------------
|
|
|
|
|
2016-07-02 00:13:29 +08:00
|
|
|
The value of the `_size` field is accessible in queries, aggregations, scripts,
|
2021-04-01 17:05:34 +08:00
|
|
|
and when sorting. It can be retrieved using the {ref}/search-fields.html#search-fields-param[fields parameter]:
|
2015-07-20 07:24:29 +08:00
|
|
|
|
2019-09-10 01:13:41 +08:00
|
|
|
[source,console]
|
2015-07-20 07:24:29 +08:00
|
|
|
--------------------------
|
|
|
|
# Example documents
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"text": "This is a document"
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001/_doc/2
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"text": "This is another document"
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:46:39 +08:00
|
|
|
GET my-index-000001/_search
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"range": {
|
2020-05-28 20:42:55 +08:00
|
|
|
"_size": { <1>
|
2015-07-20 07:24:29 +08:00
|
|
|
"gt": 10
|
|
|
|
}
|
|
|
|
}
|
2016-07-02 00:13:29 +08:00
|
|
|
},
|
|
|
|
"aggs": {
|
|
|
|
"sizes": {
|
|
|
|
"terms": {
|
2020-05-28 20:42:55 +08:00
|
|
|
"field": "_size", <2>
|
2016-07-02 00:13:29 +08:00
|
|
|
"size": 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sort": [
|
|
|
|
{
|
2020-05-28 20:42:55 +08:00
|
|
|
"_size": { <3>
|
2016-07-02 00:13:29 +08:00
|
|
|
"order": "desc"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2021-04-01 01:24:21 +08:00
|
|
|
"fields": ["_size"], <4>
|
2016-07-02 00:13:29 +08:00
|
|
|
"script_fields": {
|
|
|
|
"size": {
|
2021-04-01 01:24:21 +08:00
|
|
|
"script": "doc['_size']" <5>
|
2016-07-02 00:13:29 +08:00
|
|
|
}
|
2021-04-01 01:24:21 +08:00
|
|
|
}
|
2015-07-20 07:24:29 +08:00
|
|
|
}
|
|
|
|
--------------------------
|
2016-05-14 04:15:51 +08:00
|
|
|
// TEST[continued]
|
2015-07-20 07:24:29 +08:00
|
|
|
|
|
|
|
<1> Querying on the `_size` field
|
2016-07-05 21:12:18 +08:00
|
|
|
<2> Aggregating on the `_size` field
|
|
|
|
<3> Sorting on the `_size` field
|
2021-04-01 01:24:21 +08:00
|
|
|
<4> Use the `fields` parameter to return the `_size` in the search response.
|
|
|
|
<5> Uses a
|
2020-08-07 00:45:03 +08:00
|
|
|
{ref}/search-fields.html#script-fields[script field]
|
2020-05-28 20:42:55 +08:00
|
|
|
to return the `_size` field in the search response.
|
2021-04-01 01:24:21 +08:00
|
|
|
|