convert.asciidoc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. [[convert-processor]]
  2. === Convert Processor
  3. Converts a field in the currently ingested document to a different type, such as converting a string to an integer.
  4. If the field value is an array, all members will be converted.
  5. The supported types include: `integer`, `long`, `float`, `double`, `string`, `boolean`, and `auto`.
  6. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  7. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  8. Specifying `auto` will attempt to convert the string-valued `field` into the closest non-string type.
  9. For example, a field whose value is `"true"` will be converted to its respective boolean type: `true`. Do note
  10. that float takes precedence of double in `auto`. A value of `"242.15"` will "automatically" be converted to
  11. `242.15` of type `float`. If a provided field cannot be appropriately converted, the Convert Processor will
  12. still process successfully and leave the field value as-is. In such a case, `target_field` will
  13. still be updated with the unconverted field value.
  14. [[convert-options]]
  15. .Convert Options
  16. [options="header"]
  17. |======
  18. | Name | Required | Default | Description
  19. | `field` | yes | - | The field whose value is to be converted
  20. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  21. | `type` | yes | - | The type to convert the existing value to
  22. | `ignore_missing` | no | `false` | If `true` and `field` does not exist or is `null`, the processor quietly exits without modifying the document
  23. include::common-options.asciidoc[]
  24. |======
  25. [source,js]
  26. --------------------------------------------------
  27. PUT _ingest/pipeline/my-pipeline-id
  28. {
  29. "description": "converts the content of the id field to an integer",
  30. "processors" : [
  31. {
  32. "convert" : {
  33. "field" : "id",
  34. "type": "integer"
  35. }
  36. }
  37. ]
  38. }
  39. --------------------------------------------------
  40. // NOTCONSOLE