# Attachments questions

**URL:** https://discuss.elastic.co/t/attachments-questions/4538
**Category:** Elasticsearch
**Created:** [June 3, 2011, 12:47am UTC](https://discuss.elastic.co/t/attachments-questions/4538 "2011-06-03T00:47:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rtulloh](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@rtulloh](https://discuss.elastic.co/u/rtulloh)
#### Post date: [June 3, 2011, 12:47am UTC](https://discuss.elastic.co/t/attachments-questions/4538/1 "2011-06-03T00:47:53Z")

</div>

I am trying to index an attachment PDF. I am using 0.17.0 (built from source). My index and mapping is created like this:

curl -XPOST 10.181.18.66:9200/test -d '{  
"settings" : {  
"number\_of\_shards" : 1  
},  
"mappings" : {  
"docitem" : {  
"properties" : {  
"my\_attachment" : { "type" : "attachment" }  
}  
}  
}  
}'

I have installed the mapper-attachment and analysis-icu plugins.

[2011-06-02 17:43:45,571][INFO][plugins] [Day, Wilbur] loaded [mapper-attachments, analysis-icu], sites []

I then wrote a small java program to feed the document of interest. I tried sending in raw bytes and also sending in base64 encoded bytes when I called the API. Here is the relevant code:

public void index(Client client, String filename) throws ElasticSearchException, IOException {

```
IndexResponse response = client.prepareIndex("test", "docitem", "1")
    .setSource(jsonBuilder()
                .startObject()
                    .field("_content_type", "application/pdf")
                    .field("_name", filename)
                    .field("attachment", getBytes(filename)) // getBase64(filename)
                .endObject()
              )
    .execute()
    .actionGet();

```

}

When I search for the document, I don't see any of the attachment meta-data being created. Also, searches for any words in the content don't result in any hits. Am I missing something?

"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "docitem",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"\_content\_type":"application/pdf","\_name":"test.pdf","attachment":"JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovUHJvZHVjZXIgKEFwYWN

---

<div class="post-metadata">

### Author: ![rtulloh](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@rtulloh](https://discuss.elastic.co/u/rtulloh)
#### Post date: [June 3, 2011, 1:18am UTC](https://discuss.elastic.co/t/attachments-questions/4538/2 "2011-06-03T01:18:50Z")

</div>

Whoops, I had to change 'attachment' to 'my\_attachment' in the Java code and now things seem to be searchable as I would expect. Sorry for the bother.

public void index(Client client, String filename) throws ElasticSearchException, IOException {

```
IndexResponse response = client.prepareIndex("test", "docitem", "1")
    .setSource(jsonBuilder()
                .startObject()
                    .field("_content_type", "application/pdf")
                    .field("_name", filename)
                    .field("<b>my_attachment</b>", getBase64(filename))
                .endObject()
              )
    .execute()
    .actionGet();

```

}

---

<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, 4:04am UTC](https://discuss.elastic.co/t/attachments-questions/4538/3 "2017-07-06T04:04:46Z")

</div>


