Copy processor

The copy processor copies an entire object in an existing field to another field.

Syntax

The following is the syntax for the copy processor:

  1. {
  2. "copy": {
  3. "source_field": "source_field",
  4. "target_field": "target_field",
  5. "ignore_missing": true,
  6. "override_target": true,
  7. "remove_source": true
  8. }
  9. }

copy

Configuration parameters

The following table lists the required and optional parameters for the copy processor.

ParameterRequired/OptionalDescription
source_fieldRequiredThe name of the field to be copied. Supports template snippets.
target_fieldRequiredThe name of the field to be copied to. Supports template snippets.
ignore_missingOptionalSpecifies whether the processor should ignore documents that do not contain the specified source_field. If set to true, the processor does not modify the document if the source_field does not exist or is null. Default is false.
override_targetOptionalSpecifies whether the processor should override the target_field if it already exists in the document. If set to true, the processor overrides the value of target_field if it already exists. Default is false.
remove_sourceOptionalSpecifies whether the processor should remove the source_field after it has been copied. If set to true, the processor removes the source_field from the document. Default is false.
descriptionOptionalA brief description of the processor.
ifOptionalA condition for running the processor.
ignore_failureOptionalSpecifies whether the processor continues execution even if it encounters an error. If set to true, the failure is ignored. Default is false.
on_failureOptionalA list of processors to run if the processor fails.
tagOptionalAn identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type.

Using the processor

Follow these steps to use the processor in a pipeline.

Step 1: Create a pipeline

The following query creates a pipeline named copy_object that copies a nested object from one field to the root level:

  1. PUT /_ingest/pipeline/copy_object
  2. {
  3. "description": "Pipeline that copies object.",
  4. "processors": [
  5. {
  6. "copy": {
  7. "source_field": "message.content",
  8. "target_field":"content",
  9. "ignore_missing": true,
  10. "override_target": true,
  11. "remove_source": true
  12. }
  13. }
  14. ]
  15. }

copy

Step 2 (Optional): Test the pipeline

It is recommended that you test your pipeline before you ingest documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/copy_object/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source":{
  8. "message": {
  9. "content": {
  10. "foo": "bar",
  11. "zoo": [1, 2, 3]
  12. }
  13. }
  14. }
  15. }
  16. ]
  17. }

copy

Response

The following example response confirms that the pipeline is working as expected:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "content": {
  9. "foo": "bar",
  10. "zoo": [1, 2, 3]
  11. }
  12. },
  13. "_ingest": {
  14. "timestamp": "2023-08-24T18:02:13.218986756Z"
  15. }
  16. }
  17. }
  18. ]
  19. }

Step 3: Ingest a document

The following query ingests a document into an index named testindex1:

  1. PUT testindex1/_doc/1?pipeline=copy_object
  2. {
  3. "content": {
  4. "foo": "bar",
  5. "zoo": [1, 2, 3]
  6. }
  7. }

copy

Step 4 (Optional): Retrieve the document

To retrieve the document, run the following query:

  1. GET testindex1/_doc/1

copy