mapper-size.asciidoc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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,console]
  12. --------------------------
  13. PUT my-index-000001
  14. {
  15. "mappings": {
  16. "_size": {
  17. "enabled": true
  18. }
  19. }
  20. }
  21. --------------------------
  22. The value of the `_size` field is accessible in queries, aggregations, scripts,
  23. and when sorting:
  24. [source,console]
  25. --------------------------
  26. # Example documents
  27. PUT my-index-000001/_doc/1
  28. {
  29. "text": "This is a document"
  30. }
  31. PUT my-index-000001/_doc/2
  32. {
  33. "text": "This is another document"
  34. }
  35. GET my-index-000001/_search
  36. {
  37. "query": {
  38. "range": {
  39. "_size": { <1>
  40. "gt": 10
  41. }
  42. }
  43. },
  44. "aggs": {
  45. "sizes": {
  46. "terms": {
  47. "field": "_size", <2>
  48. "size": 10
  49. }
  50. }
  51. },
  52. "sort": [
  53. {
  54. "_size": { <3>
  55. "order": "desc"
  56. }
  57. }
  58. ],
  59. "script_fields": {
  60. "size": {
  61. "script": "doc['_size']" <4>
  62. }
  63. },
  64. "docvalue_fields": [
  65. {
  66. "field": "_size" <5>
  67. }
  68. ]
  69. }
  70. --------------------------
  71. // TEST[continued]
  72. <1> Querying on the `_size` field
  73. <2> Aggregating on the `_size` field
  74. <3> Sorting on the `_size` field
  75. <4> Uses a
  76. {ref}/search-request-body.html#request-body-search-script-fields[script field]
  77. to return the `_size` field in the search response.
  78. <5> Uses a
  79. {ref}/search-your-data.html#docvalue-fields[doc value
  80. field] to return the `_size` field in the search response. Doc value fields are
  81. useful if
  82. {ref}/modules-scripting-security.html#allowed-script-types-setting[inline
  83. scripts are disabled].