set.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. [[set-processor]]
  2. === Set processor
  3. ++++
  4. <titleabbrev>Set</titleabbrev>
  5. ++++
  6. Sets one field and associates it with the specified value. If the field already exists,
  7. its value will be replaced with the provided one.
  8. [[set-options]]
  9. .Set Options
  10. [options="header"]
  11. |======
  12. | Name | Required | Default | Description
  13. | `field` | yes | - | The field to insert, upsert, or update. Supports <<accessing-template-fields,template snippets>>.
  14. | `value` | yes* | - | The value to be set for the field. Supports <<accessing-template-fields,template snippets>>. May specify only one of `value` or `copy_from`.
  15. | `copy_from` | no | - | The origin field which will be copied to `field`, cannot set `value` simultaneously. Supported data types are `boolean`, `number`, `array`, `object`, `string`, `date`, etc.
  16. | `override` | no | true | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched.
  17. | `ignore_empty_value` | no | `false` | If `true` and `value` is a <<accessing-template-fields,template snippet>> that evaluates to `null` or the empty string, the processor quietly exits without modifying the document
  18. include::common-options.asciidoc[]
  19. |======
  20. [source,js]
  21. --------------------------------------------------
  22. {
  23. "description" : "sets the value of count to 1",
  24. "set": {
  25. "field": "count",
  26. "value": 1
  27. }
  28. }
  29. --------------------------------------------------
  30. // NOTCONSOLE
  31. This processor can also be used to copy data from one field to another. For example:
  32. [source,console]
  33. --------------------------------------------------
  34. PUT _ingest/pipeline/set_os
  35. {
  36. "description": "sets the value of host.os.name from the field os",
  37. "processors": [
  38. {
  39. "set": {
  40. "field": "host.os.name",
  41. "value": "{{os}}"
  42. }
  43. }
  44. ]
  45. }
  46. POST _ingest/pipeline/set_os/_simulate
  47. {
  48. "docs": [
  49. {
  50. "_source": {
  51. "os": "Ubuntu"
  52. }
  53. }
  54. ]
  55. }
  56. --------------------------------------------------
  57. Result:
  58. [source,console-result]
  59. --------------------------------------------------
  60. {
  61. "docs" : [
  62. {
  63. "doc" : {
  64. "_index" : "_index",
  65. "_id" : "_id",
  66. "_source" : {
  67. "host" : {
  68. "os" : {
  69. "name" : "Ubuntu"
  70. }
  71. },
  72. "os" : "Ubuntu"
  73. },
  74. "_ingest" : {
  75. "timestamp" : "2019-03-11T21:54:37.909224Z"
  76. }
  77. }
  78. }
  79. ]
  80. }
  81. --------------------------------------------------
  82. // TESTRESPONSE[s/2019-03-11T21:54:37.909224Z/$body.docs.0.doc._ingest.timestamp/]
  83. The contents of a field including complex values such as arrays and objects can be copied to another field using `copy_from`:
  84. [source,console]
  85. --------------------------------------------------
  86. PUT _ingest/pipeline/set_bar
  87. {
  88. "description": "sets the value of bar from the field foo",
  89. "processors": [
  90. {
  91. "set": {
  92. "field": "bar",
  93. "copy_from": "foo"
  94. }
  95. }
  96. ]
  97. }
  98. POST _ingest/pipeline/set_bar/_simulate
  99. {
  100. "docs": [
  101. {
  102. "_source": {
  103. "foo": ["foo1", "foo2"]
  104. }
  105. }
  106. ]
  107. }
  108. --------------------------------------------------
  109. Result:
  110. [source,console-result]
  111. --------------------------------------------------
  112. {
  113. "docs" : [
  114. {
  115. "doc" : {
  116. "_index" : "_index",
  117. "_id" : "_id",
  118. "_source" : {
  119. "bar": ["foo1", "foo2"],
  120. "foo": ["foo1", "foo2"]
  121. },
  122. "_ingest" : {
  123. "timestamp" : "2020-09-30T12:55:17.742795Z"
  124. }
  125. }
  126. }
  127. ]
  128. }
  129. --------------------------------------------------
  130. // TESTRESPONSE[s/2020-09-30T12:55:17.742795Z/$body.docs.0.doc._ingest.timestamp/]