# Can Attachment type do not store base64 source?

**URL:** <https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938>\
**Category:** Elasticsearch\
**Created:** [May 20, 2015, 3:06am UTC](https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938 "2015-05-20T03:06:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinyke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinyke/32/587_2.png) [@shinyke](https://discuss.elastic.co/u/shinyke)\
**Post date:** [May 20, 2015, 3:06am UTC](https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938/1 "2015-05-20T03:06:57Z")

</div>

Hi,I'm a new to ES, our project is about email.

Recently, we try to index attachments with Attachment Type.What confused us is that Although we only need the content index, ES still store file's base64 string in \_source. I am afraid that this may cost a lot of hard disk space.

Is there some way to solve the problem？Is it possible to index content and discard base64 string？

Thanks,  
Shiny ke

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [May 20, 2015, 5:01am UTC](https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938/2 "2015-05-20T05:01:54Z")

</div>

Hi shinyke,

You can control to include/exclude \_source in your mappings.  
See : [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#include-exclude](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#include-exclude)

Example :

```json
PUT /attachment_sample
{
  "mappings": {
    "files": {
      "_source": {
        "excludes" : ["my_attachments"]
      }, 
      "properties": {
        "my_attachments" : { "type": "attachment" },
        "title": { "type": "string" }
      }
    }
  }
}

PUT /attachment_sample/files/1
{
  "title": "fuga",
  "my_attachments" : "...base64 string..."
}

GET /attachment_sample/files/_search
#then, _source include only title
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "attachment_sample",
            "_type": "files",
            "_id": "1",
            "_score": 1,
            "_source": {
               "title": "fuga"
            }
         }
      ]
   }
}

```

Does it make sense?

---

<div class="post-metadata">

**Author:** ![shinyke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinyke/32/587_2.png) [@shinyke](https://discuss.elastic.co/u/shinyke)\
**Post date:** [May 20, 2015, 7:18am UTC](https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938/3 "2015-05-20T07:18:28Z")

</div>

Yes, I try exclude \_source sentence and it work fine!

Many Thx~! johtani

---

<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:** [July 6, 2017, 12:13am UTC](https://discuss.elastic.co/t/can-attachment-type-do-not-store-base64-source/938/4 "2017-07-06T00:13:13Z")

</div>


