mapper-size.asciidoc 1.5 KB

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