mapper-size.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. [[mapper-size]]
  2. === Mapper Size Plugin
  3. The mapper-size plugin provides the `_size` meta field which, when enabled,
  4. indexes the size in bytes of the original
  5. {ref}/mapping-source-field.html[`_source`] field.
  6. [[mapper-size-install]]
  7. [float]
  8. ==== Installation
  9. This plugin can be installed using the plugin manager:
  10. [source,sh]
  11. ----------------------------------------------------------------
  12. sudo bin/elasticsearch-plugin install mapper-size
  13. ----------------------------------------------------------------
  14. The plugin must be installed on every node in the cluster, and each node must
  15. be restarted after installation.
  16. [[mapper-size-remove]]
  17. [float]
  18. ==== Removal
  19. The plugin can be removed with the following command:
  20. [source,sh]
  21. ----------------------------------------------------------------
  22. sudo bin/elasticsearch-plugin remove mapper-size
  23. ----------------------------------------------------------------
  24. The node must be stopped before removing the plugin.
  25. [[mapper-size-usage]]
  26. ==== Using the `_size` field
  27. In order to enable the `_size` field, set the mapping as follows:
  28. [source,js]
  29. --------------------------
  30. PUT my_index
  31. {
  32. "mappings": {
  33. "my_type": {
  34. "_size": {
  35. "enabled": true
  36. }
  37. }
  38. }
  39. }
  40. --------------------------
  41. // CONSOLE
  42. The value of the `_size` field is accessible in queries, aggregations, scripts,
  43. and when sorting:
  44. [source,js]
  45. --------------------------
  46. # Example documents
  47. PUT my_index/my_type/1
  48. {
  49. "text": "This is a document"
  50. }
  51. PUT my_index/my_type/2
  52. {
  53. "text": "This is another document"
  54. }
  55. GET my_index/_search
  56. {
  57. "query": {
  58. "range": {
  59. "_size": { <1>
  60. "gt": 10
  61. }
  62. }
  63. },
  64. "aggs": {
  65. "sizes": {
  66. "terms": {
  67. "field": "_size", <2>
  68. "size": 10
  69. }
  70. }
  71. },
  72. "sort": [
  73. {
  74. "_size": { <3>
  75. "order": "desc"
  76. }
  77. }
  78. ],
  79. "script_fields": {
  80. "size": {
  81. "script": "doc['_size']" <4>
  82. }
  83. }
  84. }
  85. --------------------------
  86. // CONSOLE
  87. // TEST[continued]
  88. <1> Querying on the `_size` field
  89. <2> Aggregating on the `_size` field
  90. <3> Sorting on the `_size` field
  91. <4> Accessing the `_size` field in scripts (inline scripts must be modules-security-scripting.html#enable-dynamic-scripting[enabled] for this example to work)