mapper-size.asciidoc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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
  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/_doc/1
  28. {
  29. "text": "This is a document"
  30. }
  31. PUT my_index/_doc/2
  32. {
  33. "text": "This is another document"
  34. }
  35. GET my_index/_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. }
  65. --------------------------
  66. // TEST[continued]
  67. <1> Querying on the `_size` field
  68. <2> Aggregating on the `_size` field
  69. <3> Sorting on the `_size` field
  70. <4> Accessing the `_size` field in scripts (inline scripts must be modules-security-scripting.html#enable-dynamic-scripting[enabled] for this example to work)