set.asciidoc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,js]
  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. // CONSOLE
  53. Result:
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "docs" : [
  58. {
  59. "doc" : {
  60. "_index" : "_index",
  61. "_type" : "_doc",
  62. "_id" : "_id",
  63. "_source" : {
  64. "host" : {
  65. "os" : {
  66. "name" : "Ubuntu"
  67. }
  68. },
  69. "os" : "Ubuntu"
  70. },
  71. "_ingest" : {
  72. "timestamp" : "2019-03-11T21:54:37.909224Z"
  73. }
  74. }
  75. }
  76. ]
  77. }
  78. --------------------------------------------------
  79. // TESTRESPONSE[s/2019-03-11T21:54:37.909224Z/$body.docs.0.doc._ingest.timestamp/]