dot-expand.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. [[dot-expand-processor]]
  2. === Dot expander processor
  3. ++++
  4. <titleabbrev>Dot expander</titleabbrev>
  5. ++++
  6. Expands a field with dots into an object field. This processor allows fields
  7. with dots in the name to be accessible by other processors in the pipeline.
  8. Otherwise these fields can't be accessed by any processor.
  9. [[dot-expander-options]]
  10. .Dot Expand Options
  11. [options="header"]
  12. |======
  13. | Name | Required | Default | Description
  14. | `field` | yes | - | The field to expand into an object field. If set to `*`, all top-level fields will be expanded.
  15. | `path` | no | - | The field that contains the field to expand. Only required if the field to expand is part another object field, because the `field` option can only understand leaf fields.
  16. | `override`| no | false | Controls the behavior when there is already an existing nested object that conflicts with the expanded field. When `false`, the processor will merge conflicts by combining the old and the new values into an array. When `true`, the value from the expanded field will overwrite the existing value.
  17. include::common-options.asciidoc[]
  18. |======
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "dot_expander": {
  23. "field": "foo.bar"
  24. }
  25. }
  26. --------------------------------------------------
  27. // NOTCONSOLE
  28. For example the dot expand processor would turn this document:
  29. [source,js]
  30. --------------------------------------------------
  31. {
  32. "foo.bar" : "value"
  33. }
  34. --------------------------------------------------
  35. // NOTCONSOLE
  36. into:
  37. [source,js]
  38. --------------------------------------------------
  39. {
  40. "foo" : {
  41. "bar" : "value"
  42. }
  43. }
  44. --------------------------------------------------
  45. // NOTCONSOLE
  46. If there is already a `bar` field nested under `foo` then
  47. this processor merges the `foo.bar` field into it. If the field is
  48. a scalar value then it will turn that field into an array field.
  49. For example, the following document:
  50. [source,js]
  51. --------------------------------------------------
  52. {
  53. "foo.bar" : "value2",
  54. "foo" : {
  55. "bar" : "value1"
  56. }
  57. }
  58. --------------------------------------------------
  59. // NOTCONSOLE
  60. is transformed by the `dot_expander` processor into:
  61. [source,js]
  62. --------------------------------------------------
  63. {
  64. "foo" : {
  65. "bar" : ["value1", "value2"]
  66. }
  67. }
  68. --------------------------------------------------
  69. // NOTCONSOLE
  70. Contrast that with when the `override` option is set to `true`.
  71. [source,js]
  72. --------------------------------------------------
  73. {
  74. "dot_expander": {
  75. "field": "foo.bar",
  76. "override": true
  77. }
  78. }
  79. --------------------------------------------------
  80. // NOTCONSOLE
  81. In that case, the value of the expanded field overrides the value of the nested object.
  82. [source,js]
  83. --------------------------------------------------
  84. {
  85. "foo" : {
  86. "bar" : "value2"
  87. }
  88. }
  89. --------------------------------------------------
  90. // NOTCONSOLE
  91. '''
  92. The value of `field` can also be set to a `*` to expand all top-level dotted field names:
  93. [source,js]
  94. --------------------------------------------------
  95. {
  96. "dot_expander": {
  97. "field": "*"
  98. }
  99. }
  100. --------------------------------------------------
  101. // NOTCONSOLE
  102. The dot expand processor would turn this document:
  103. [source,js]
  104. --------------------------------------------------
  105. {
  106. "foo.bar" : "value",
  107. "baz.qux" : "value"
  108. }
  109. --------------------------------------------------
  110. // NOTCONSOLE
  111. into:
  112. [source,js]
  113. --------------------------------------------------
  114. {
  115. "foo" : {
  116. "bar" : "value"
  117. },
  118. "baz" : {
  119. "qux" : "value"
  120. }
  121. }
  122. --------------------------------------------------
  123. // NOTCONSOLE
  124. '''
  125. If any field outside of the leaf field conflicts with a pre-existing field of the same name,
  126. then that field needs to be renamed first.
  127. Consider the following document:
  128. [source,js]
  129. --------------------------------------------------
  130. {
  131. "foo": "value1",
  132. "foo.bar": "value2"
  133. }
  134. --------------------------------------------------
  135. // NOTCONSOLE
  136. Then the `foo` needs to be renamed first before the `dot_expander`
  137. processor is applied. So in order for the `foo.bar` field to properly
  138. be expanded into the `bar` field under the `foo` field the following
  139. pipeline should be used:
  140. [source,js]
  141. --------------------------------------------------
  142. {
  143. "processors" : [
  144. {
  145. "rename" : {
  146. "field" : "foo",
  147. "target_field" : "foo.bar"
  148. }
  149. },
  150. {
  151. "dot_expander": {
  152. "field": "foo.bar"
  153. }
  154. }
  155. ]
  156. }
  157. --------------------------------------------------
  158. // NOTCONSOLE
  159. The reason for this is that Ingest doesn't know how to automatically cast
  160. a scalar field to an object field.