set.asciidoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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>>.
  15. | `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.
  16. | `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
  17. include::common-options.asciidoc[]
  18. |======
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "description" : "sets the value of count to 1",
  23. "set": {
  24. "field": "count",
  25. "value": 1
  26. }
  27. }
  28. --------------------------------------------------
  29. // NOTCONSOLE
  30. This processor can also be used to copy data from one field to another. For example:
  31. [source,console]
  32. --------------------------------------------------
  33. PUT _ingest/pipeline/set_os
  34. {
  35. "description": "sets the value of host.os.name from the field os",
  36. "processors": [
  37. {
  38. "set": {
  39. "field": "host.os.name",
  40. "value": "{{os}}"
  41. }
  42. }
  43. ]
  44. }
  45. POST _ingest/pipeline/set_os/_simulate
  46. {
  47. "docs": [
  48. {
  49. "_source": {
  50. "os": "Ubuntu"
  51. }
  52. }
  53. ]
  54. }
  55. --------------------------------------------------
  56. Result:
  57. [source,console-result]
  58. --------------------------------------------------
  59. {
  60. "docs" : [
  61. {
  62. "doc" : {
  63. "_index" : "_index",
  64. "_id" : "_id",
  65. "_source" : {
  66. "host" : {
  67. "os" : {
  68. "name" : "Ubuntu"
  69. }
  70. },
  71. "os" : "Ubuntu"
  72. },
  73. "_ingest" : {
  74. "timestamp" : "2019-03-11T21:54:37.909224Z"
  75. }
  76. }
  77. }
  78. ]
  79. }
  80. --------------------------------------------------
  81. // TESTRESPONSE[s/2019-03-11T21:54:37.909224Z/$body.docs.0.doc._ingest.timestamp/]