mapper-size.asciidoc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. [[mapper-size]]
  2. === Mapper size plugin
  3. The mapper-size plugin provides the `_size` metadata 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. It can be retrieved using the {ref}/search-fields.html#search-fields-param[fields parameter]:
  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. "fields": ["_size"], <4>
  60. "script_fields": {
  61. "size": {
  62. "script": "doc['_size']" <5>
  63. }
  64. }
  65. }
  66. --------------------------
  67. // TEST[continued]
  68. <1> Querying on the `_size` field
  69. <2> Aggregating on the `_size` field
  70. <3> Sorting on the `_size` field
  71. <4> Use the `fields` parameter to return the `_size` in the search response.
  72. <5> Uses a
  73. {ref}/search-fields.html#script-fields[script field]
  74. to return the `_size` field in the search response.
  75. [NOTE]
  76. .Using `_size` in {kib}
  77. ================================================
  78. To use the `_size` field in {kib}, update the `metaFields` setting and add
  79. `_size` to the list of meta fields. `metaFields` can be configured in {kib}
  80. from the Advanced Settings page in Management.
  81. ================================================