mapper-size.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. :plugin_name: mapper-size
  7. include::install_remove.asciidoc[]
  8. [[mapper-size-usage]]
  9. ==== Using the `_size` field
  10. In order to enable the `_size` field, set the mapping as follows:
  11. [source,js]
  12. --------------------------
  13. PUT my_index
  14. {
  15. "mappings": {
  16. "_doc": {
  17. "_size": {
  18. "enabled": true
  19. }
  20. }
  21. }
  22. }
  23. --------------------------
  24. // CONSOLE
  25. The value of the `_size` field is accessible in queries, aggregations, scripts,
  26. and when sorting:
  27. [source,js]
  28. --------------------------
  29. # Example documents
  30. PUT my_index/_doc/1
  31. {
  32. "text": "This is a document"
  33. }
  34. PUT my_index/_doc/2
  35. {
  36. "text": "This is another document"
  37. }
  38. GET my_index/_search
  39. {
  40. "query": {
  41. "range": {
  42. "_size": { <1>
  43. "gt": 10
  44. }
  45. }
  46. },
  47. "aggs": {
  48. "sizes": {
  49. "terms": {
  50. "field": "_size", <2>
  51. "size": 10
  52. }
  53. }
  54. },
  55. "sort": [
  56. {
  57. "_size": { <3>
  58. "order": "desc"
  59. }
  60. }
  61. ],
  62. "script_fields": {
  63. "size": {
  64. "script": "doc['_size']" <4>
  65. }
  66. }
  67. }
  68. --------------------------
  69. // CONSOLE
  70. // TEST[continued]
  71. <1> Querying on the `_size` field
  72. <2> Aggregating on the `_size` field
  73. <3> Sorting on the `_size` field
  74. <4> Accessing the `_size` field in scripts (inline scripts must be modules-security-scripting.html#enable-dynamic-scripting[enabled] for this example to work)