# Ingest-attachment using CBOR sample

**URL:** <https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818>\
**Category:** Elasticsearch\
**Created:** [November 28, 2019, 9:44am UTC](https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818 "2019-11-28T09:44:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carantunes](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@carantunes](https://discuss.elastic.co/u/carantunes)\
**Post date:** [November 28, 2019, 9:44am UTC](https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818/1 "2019-11-28T09:44:29Z")

</div>

Looks like this is still an issue today, more than a year later.

> [@Ingest-attachment using CBOR examples](https://discuss.elastic.co/t/ingest-attachment-using-cbor-examples/93832):
>
> Need some clarification regarding the following thread: Alex says: The trick is to just use the cbor builder to create your content, and add a bytearray to the field, you want to process instead of a base64 encoded string. What exactly is meant by "add a bytearray to the field?" I have been mapping an 'attachment-data' field with type 'keyword' and writing to that a base64 encoded string through the pipeline. I'm using ruby client library to encode the data. Now, I'm trying to cbor the at…

Can you provide a working sample of how to use ingest-attachment with cbor?  
I'm struggling with processing large files.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 29, 2019, 8:03am UTC](https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818/2 "2019-11-29T08:03:48Z")

</div>

hey,

you need to find a library for your progamming language that creates CBOR, so that the whole document including all fields is sent as CBOR, not only the attachment itself.

Does that make sense?

--Alex

---

<div class="post-metadata">

**Author:** ![carantunes](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@carantunes](https://discuss.elastic.co/u/carantunes)\
**Post date:** [November 29, 2019, 9:23am UTC](https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818/3 "2019-11-29T09:23:27Z")

</div>

Thank you.

For anyone struggling out there, here's a very basic working python sample, based on this configuration:

```auto
PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field" : "data"
      }
    }
  ]
}

```

Sample:

```auto
import cbor2
import requests

filename = 'some-file'
headers = {'content-type': 'application/cbor'}

with open(filename, 'rb') as f:
    doc = {
        'data': f.read()
    }
    requests.put(
        'http://localhost:9200/my_index/my_type/my_id?pipeline=attachment&pretty', 
        data=cbor2.dumps(doc), 
        headers=headers
    )

```

Be aware however that not all clients have support. The python client for example doesn't allow custom headers on the index method ([https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/client/ **init**.py#L330](https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/client/ __init__.py#L330) )

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 27, 2019, 9:23am UTC](https://discuss.elastic.co/t/ingest-attachment-using-cbor-sample/209818/4 "2019-12-27T09:23:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
