synthetic-source.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. [[synthetic-source]]
  2. ==== Synthetic `_source`
  3. IMPORTANT: Synthetic `_source` is Generally Available only for TSDB indices
  4. (indices that have `index.mode` set to `time_series`). For other indices
  5. synthetic `_source` is in technical preview. Features in technical preview may
  6. be changed or removed in a future release. Elastic will apply best effort to fix
  7. any issues, but features in technical preview are not subject to the support SLA
  8. of official GA features.
  9. Though very handy to have around, the source field takes up a significant amount
  10. of space on disk. Instead of storing source documents on disk exactly as you
  11. send them, Elasticsearch can reconstruct source content on the fly upon retrieval.
  12. Enable this by setting `mode: synthetic` in `_source`:
  13. [source,console,id=enable-synthetic-source-example]
  14. ----
  15. PUT idx
  16. {
  17. "mappings": {
  18. "_source": {
  19. "mode": "synthetic"
  20. }
  21. }
  22. }
  23. ----
  24. // TESTSETUP
  25. While this on the fly reconstruction is *generally* slower than saving the source
  26. documents verbatim and loading them at query time, it saves a lot of storage
  27. space. There are a couple of restrictions to be aware of:
  28. * When you retrieve synthetic `_source` content it undergoes minor
  29. <<synthetic-source-modifications,modifications>> compared to the original JSON.
  30. * Synthetic `_source` can be used with indices that contain only these field
  31. types:
  32. ** <<aggregate-metric-double-synthetic-source, `aggregate_metric_double`>>
  33. ** <<boolean-synthetic-source,`boolean`>>
  34. ** <<numeric-synthetic-source,`byte`>>
  35. ** <<date-synthetic-source,`date`>>
  36. ** <<date-nanos-synthetic-source,`date_nanos`>>
  37. ** <<dense-vector-synthetic-source,`dense_vector`>>
  38. ** <<numeric-synthetic-source,`double`>>
  39. ** <<numeric-synthetic-source,`float`>>
  40. ** <<geo-point-synthetic-source,`geo_point`>>
  41. ** <<numeric-synthetic-source,`half_float`>>
  42. ** <<histogram-synthetic-source,`histogram`>>
  43. ** <<numeric-synthetic-source,`integer`>>
  44. ** <<ip-synthetic-source,`ip`>>
  45. ** <<keyword-synthetic-source,`keyword`>>
  46. ** <<numeric-synthetic-source,`long`>>
  47. ** <<numeric-synthetic-source,`scaled_float`>>
  48. ** <<numeric-synthetic-source,`short`>>
  49. ** <<text-synthetic-source,`text`>>
  50. ** <<version-synthetic-source,`version`>>
  51. ** <<wildcard-synthetic-source,`wildcard`>>
  52. Runtime fields cannot, at this stage, use synthetic `_source`.
  53. [[synthetic-source-modifications]]
  54. ===== Synthetic `_source` modifications
  55. When synthetic `_source` is enabled, retrieved documents undergo some
  56. modifications compared to the original JSON.
  57. [[synthetic-source-modifications-leaf-arrays]]
  58. ====== Arrays moved to leaf fields
  59. Synthetic `_source` arrays are moved to leaves. For example:
  60. [source,console,id=synthetic-source-leaf-arrays-example]
  61. ----
  62. PUT idx/_doc/1
  63. {
  64. "foo": [
  65. {
  66. "bar": 1
  67. },
  68. {
  69. "bar": 2
  70. }
  71. ]
  72. }
  73. ----
  74. // TEST[s/$/\nGET idx\/_doc\/1?filter_path=_source\n/]
  75. Will become:
  76. [source,console-result]
  77. ----
  78. {
  79. "foo": {
  80. "bar": [1, 2]
  81. }
  82. }
  83. ----
  84. // TEST[s/^/{"_source":/ s/\n$/}/]
  85. [[synthetic-source-modifications-field-names]]
  86. ====== Fields named as they are mapped
  87. Synthetic source names fields as they are named in the mapping. When used
  88. with <<dynamic,dynamic mapping>>, fields with dots (`.`) in their names are, by
  89. default, interpreted as multiple objects, while dots in field names are
  90. preserved within objects that have <<subobjects>> disabled. For example:
  91. [source,console,id=synthetic-source-objecty-example]
  92. ----
  93. PUT idx/_doc/1
  94. {
  95. "foo.bar.baz": 1
  96. }
  97. ----
  98. // TEST[s/$/\nGET idx\/_doc\/1?filter_path=_source\n/]
  99. Will become:
  100. [source,console-result]
  101. ----
  102. {
  103. "foo": {
  104. "bar": {
  105. "baz": 1
  106. }
  107. }
  108. }
  109. ----
  110. // TEST[s/^/{"_source":/ s/\n$/}/]
  111. [[synthetic-source-modifications-alphabetical]]
  112. ====== Alphabetical sorting
  113. Synthetic `_source` fields are sorted alphabetically. The
  114. https://www.rfc-editor.org/rfc/rfc7159.html[JSON RFC] defines objects as
  115. "an unordered collection of zero or more name/value pairs" so applications
  116. shouldn't care but without synthetic `_source` the original ordering is
  117. preserved and some applications may, counter to the spec, do something with
  118. that ordering.