The attachment processor lets Elasticsearch extract file attachments in common formats (such as PPT, XLS, and PDF) by using the Apache text extraction library [Tika](https://tika.apache.org/).
The source field must be a base64 encoded binary. If you do not want to incur the overhead of converting back and forth between base64, you can use the CBOR format instead of JSON and specify the field as a bytes array instead of a string representation. The processor will skip the base64 decoding then.
## Using the attachment processor in a pipeline [using-attachment]
$$$attachment-options$$$
| Name | Required | Default | Description |
| --- | --- | --- | --- |
| `field` | yes | - | The field to get the base64 encoded field from |
| `target_field` | no | attachment | The field that will hold the attachment information |
| `indexed_chars` | no | 100000 | The number of chars being used for extraction to prevent huge fields. Use `-1` for no limit. |
| `indexed_chars_field` | no | `null` | Field name from which you can overwrite the number of chars being used for extraction. See `indexed_chars`. |
| `properties` | no | all properties | Array of properties to select to be stored. Can be `content`, `title`, `name`, `author`, `keywords`, `date`, `content_type`, `content_length`, `language` |
| `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document |
| `remove_binary` | encouraged | `false` | If `true`, the binary `field` will be removed from the document. This option is not required, but setting it explicitly is encouraged, and omitting it will result in a warning. |
| `resource_name` | no | | Field containing the name of the resource to decode. If specified, the processor passes this resource name to the underlying Tika library to enable [Resource Name Based Detection](https://tika.apache.org/1.24.1/detection.html#Resource_Name_Based_Detection). |
If attaching files to JSON documents, you must first encode the file as a base64 string. On Unix-like systems, you can do this using a `base64` command:
The command returns the base64-encoded string for the file. The following base64 string is for an `.rtf` file containing the text `Lorem ipsum dolor sit amet`: `e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=`.
Extracting contents from binary data is a resource intensive operation and consumes a lot of resources. It is highly recommended to run pipelines using this processor in a dedicated ingest node.
Keeping the binary as a field within the document might consume a lot of resources. It is highly recommended to remove that field from the document, by setting `remove_binary` to `true` to automatically remove the field, as in the other examples shown on this page. If you *do* want to keep the binary field, explicitly set `remove_binary` to `false` to avoid the warning you get from omitting it:
To avoid encoding and decoding JSON to base64, you can instead pass CBOR data to the attachment processor. For example, the following request creates the `cbor-attachment` pipeline, which uses the attachment processor.
The following Python script passes CBOR data to an HTTP indexing request that includes the `cbor-attachment` pipeline. The HTTP request headers use a `content-type` of `application/cbor`.
To prevent extracting too many chars and overload the node memory, the number of chars being used for extraction is limited by default to `100000`. You can change this value by setting `indexed_chars`. Use `-1` for no limit but ensure when setting this that your node will have enough HEAP to extract the content of very big documents.
You can also define this limit per document by extracting from a given field the limit to set. If the document has that field, it will overwrite the `indexed_chars` setting. To set this field, define the `indexed_chars_field` setting.
To use the attachment processor within an array of attachments the [foreach processor](/reference/enrich-processor/foreach-processor.md) is required. This enables the attachment processor to be run on the individual elements of the array.
In this case, we want to process the data field in each element of the attachments field and insert the properties into the document so the following `foreach` processor is used:
Note that the `target_field` needs to be set, otherwise the default value is used which is a top level field `attachment`. The properties on this top level field will contain the value of the first attachment only. However, by specifying the `target_field` on to a value on `_ingest._value` it will correctly associate the properties with the correct attachment.