mapper-size.asciidoc 2.2 KB

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