| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | [[mapper-size]]=== Mapper Size PluginThe 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.[[mapper-size-install]][float]==== InstallationThis plugin can be installed using the plugin manager:[source,sh]----------------------------------------------------------------sudo bin/elasticsearch-plugin install mapper-size----------------------------------------------------------------The plugin must be installed on every node in the cluster, and each node mustbe restarted after installation.[[mapper-size-remove]][float]==== RemovalThe plugin can be removed with the following command:[source,sh]----------------------------------------------------------------sudo bin/elasticsearch-plugin remove mapper-size----------------------------------------------------------------The node must be stopped before removing the plugin.[[mapper-size-usage]]==== Using the `_size` fieldIn order to enable the `_size` field, set the mapping as follows:[source,js]--------------------------PUT my_index{  "mappings": {    "my_type": {      "_size": {        "enabled": true      }    }  }}--------------------------// CONSOLEThe value of the `_size` field is accessible in queries, aggregations, scripts,and when sorting:[source,js]--------------------------# Example documentsPUT my_index/my_type/1{  "text": "This is a document"}PUT my_index/my_type/2{  "text": "This is another document"}GET my_index/_search{  "query": {    "range": {      "_size": { <1>        "gt": 10      }    }  },  "aggs": {    "sizes": {      "terms": {        "field": "_size", <2>        "size": 10      }    }  },  "sort": [    {      "_size": { <3>        "order": "desc"      }    }  ],  "script_fields": {    "size": {      "script": "doc['_size']"  <4>    }  }}--------------------------// CONSOLE// TEST[continued]<1> Querying on the `_size` field<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)
 |