set.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [[set-processor]]
  2. === Set Processor
  3. Sets one field and associates it with the specified value. If the field already exists,
  4. its value will be replaced with the provided one.
  5. [[set-options]]
  6. .Set Options
  7. [options="header"]
  8. |======
  9. | Name | Required | Default | Description
  10. | `field` | yes | - | The field to insert, upsert, or update. Supports <<accessing-template-fields,template snippets>>.
  11. | `value` | yes | - | The value to be set for the field. Supports <<accessing-template-fields,template snippets>>.
  12. | `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.
  13. include::common-options.asciidoc[]
  14. |======
  15. [source,js]
  16. --------------------------------------------------
  17. {
  18. "description" : "sets the value of count to 1",
  19. "set": {
  20. "field": "count",
  21. "value": 1
  22. }
  23. }
  24. --------------------------------------------------
  25. // NOTCONSOLE
  26. This processor can also be used to copy data from one field to another. For example:
  27. [source,console]
  28. --------------------------------------------------
  29. PUT _ingest/pipeline/set_os
  30. {
  31. "description": "sets the value of host.os.name from the field os",
  32. "processors": [
  33. {
  34. "set": {
  35. "field": "host.os.name",
  36. "value": "{{os}}"
  37. }
  38. }
  39. ]
  40. }
  41. POST _ingest/pipeline/set_os/_simulate
  42. {
  43. "docs": [
  44. {
  45. "_source": {
  46. "os": "Ubuntu"
  47. }
  48. }
  49. ]
  50. }
  51. --------------------------------------------------
  52. Result:
  53. [source,console-result]
  54. --------------------------------------------------
  55. {
  56. "docs" : [
  57. {
  58. "doc" : {
  59. "_index" : "_index",
  60. "_id" : "_id",
  61. "_source" : {
  62. "host" : {
  63. "os" : {
  64. "name" : "Ubuntu"
  65. }
  66. },
  67. "os" : "Ubuntu"
  68. },
  69. "_ingest" : {
  70. "timestamp" : "2019-03-11T21:54:37.909224Z"
  71. }
  72. }
  73. }
  74. ]
  75. }
  76. --------------------------------------------------
  77. // TESTRESPONSE[s/2019-03-11T21:54:37.909224Z/$body.docs.0.doc._ingest.timestamp/]