<commit_before>[[mapper-size]]
=== Mapper Size Plugin

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.

[[mapper-size-install]]
[float]
==== Installation

This plugin can be installed using the plugin manager:

[source,sh]
----------------------------------------------------------------
sudo bin/plugin install mapper-size
----------------------------------------------------------------

The plugin must be installed on every node in the cluster, and each node must
be restarted after installation.

[[mapper-size-remove]]
[float]
==== Removal

The plugin can be removed with the following command:

[source,sh]
----------------------------------------------------------------
sudo bin/plugin remove mapper-size
----------------------------------------------------------------

The node must be stopped before removing the plugin.

[[mapper-size-usage]]
==== Using the `_size` field

In order to enable the `_size` field, set the mapping as follows:

[source,js]
--------------------------
PUT my_index
{
  "mappings": {
    "my_type": {
      "_size": {
        "enabled": true
      }
    }
  }
}
--------------------------
// AUTOSENSE

The value of the `_size` field is accessible in queries, aggregations, scripts,
and when sorting:

[source,js]
--------------------------
# Example documents
PUT 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>
    }
  }
}
--------------------------
// AUTOSENSE

<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 <<enable-dynamic-scripting,enabled>> for this example to work)
<commit_msg>Docs: Fixed bad link to dynamic scripting<commit_after>[[mapper-size]]
=== Mapper Size Plugin

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.

[[mapper-size-install]]
[float]
==== Installation

This plugin can be installed using the plugin manager:

[source,sh]
----------------------------------------------------------------
sudo bin/plugin install mapper-size
----------------------------------------------------------------

The plugin must be installed on every node in the cluster, and each node must
be restarted after installation.

[[mapper-size-remove]]
[float]
==== Removal

The plugin can be removed with the following command:

[source,sh]
----------------------------------------------------------------
sudo bin/plugin remove mapper-size
----------------------------------------------------------------

The node must be stopped before removing the plugin.

[[mapper-size-usage]]
==== Using the `_size` field

In order to enable the `_size` field, set the mapping as follows:

[source,js]
--------------------------
PUT my_index
{
  "mappings": {
    "my_type": {
      "_size": {
        "enabled": true
      }
    }
  }
}
--------------------------
// AUTOSENSE

The value of the `_size` field is accessible in queries, aggregations, scripts,
and when sorting:

[source,js]
--------------------------
# Example documents
PUT 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>
    }
  }
}
--------------------------
// AUTOSENSE

<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-scripting.html#enable-dynamic-scripting[enabled] for this example to work)

{'fraction_non_alphanumeric': 0.27433035714285714, 'fraction_numerical': 0.00625, 'mean_word_length': 1.704284852142426, 'pattern_counts': {'":': 42, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6417675', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1313, 'n_words': 420}