# Having trouble storing attachments. What am I doing wrong?

**URL:** https://discuss.elastic.co/t/having-trouble-storing-attachments-what-am-i-doing-wrong/12021
**Category:** Elasticsearch
**Created:** [May 18, 2013, 8:42pm UTC](https://discuss.elastic.co/t/having-trouble-storing-attachments-what-am-i-doing-wrong/12021 "2013-05-18T20:42:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Soep\_2](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Andrew\_Soep\_2](https://discuss.elastic.co/u/Andrew_Soep_2)
#### Post date: [May 18, 2013, 8:42pm UTC](https://discuss.elastic.co/t/having-trouble-storing-attachments-what-am-i-doing-wrong/12021/1 "2013-05-18T20:42:28Z")

</div>

I've been trying to get attachments to store for days now, and I can't seem  
to get it to work. I've tried a number of different solutions, and I can't  
seem to get anything to work, so I'm hoping someone here can point me in  
the right direction.

I'm using ES .20.5 with the latest attachment plugin. This is my mapping:

pcc\_doc: {

- \_boost: {
  - null\_value: 1  
}

- properties: {
  - content: {
    - path: full
    - type: attachment
    - fields: {
      - content: {
        - type: string  
}

      - author: {
        - type: string  
}

      - title: {
        - analyzer: english
        - type: string  
}

      - keywords: {
        - store: yes
        - analyzer: keyword
        - type: string  
}

      - name: {
        - type: string  
}

      - date: {
        - format: dateOptionalTime
        - type: date  
}

      - content\_type: {
        - type: string  
}  
}  
}

I'm using Elastica to store the document (in this case a PDF) and my code  
looks like this:

$elasticaClient = new \Elastica\Client();  
$elasticaIndex = $elasticaClient-\>getIndex($company);  
$elasticaType = $elasticaIndex-\>getType($category);  
$researchDocument = new \Elastica\Document();  
$researchDocument-\>addFileContent('content', file\_get\_contents($path));  
// Add to type  
$elasticaType-\>addDocument($researchDocument);

// Refresh Index  
$elasticaType-\>getIndex()-\>refresh();

Upon successful submit, I see one document inserted, and the content field  
is filled with a string of jibberish (  
JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGF) \<-- is a small  
paste of what is in the field I try to do a search on the type for the text  
that I know is in the PDF, but ES returns the message: curl: (52) Empty  
reply from server

I was under the impression that if I provided for those other fields, the  
attachment plugin would fill them in automatically.

Can anyone see something wrong in what I'm doing? I'm really stuck here.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 19, 2013, 2:20am UTC](https://discuss.elastic.co/t/having-trouble-storing-attachments-what-am-i-doing-wrong/12021/2 "2013-05-19T02:20:39Z")

</div>

Can you post your search request?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 18 mai 2013 à 22:42, Andrew Soep [siraris@gmail.com](mailto:siraris@gmail.com) a écrit :

I've been trying to get attachments to store for days now, and I can't seem to get it to work. I've tried a number of different solutions, and I can't seem to get anything to work, so I'm hoping someone here can point me in the right direction.

I'm using ES .20.5 with the latest attachment plugin. This is my mapping:

pcc\_doc: {  
\_boost: {  
null\_value: 1  
}  
properties: {  
content: {  
path: full  
type: attachment  
fields: {  
content: {  
type: string  
}  
author: {  
type: string  
}  
title: {  
analyzer: english  
type: string  
}  
keywords: {  
store: yes  
analyzer: keyword  
type: string  
}  
name: {  
type: string  
}  
date: {  
format: dateOptionalTime  
type: date  
}  
content\_type: {  
type: string  
}  
}  
}

I'm using Elastica to store the document (in this case a PDF) and my code looks like this:

$elasticaClient = new \Elastica\Client();  
$elasticaIndex = $elasticaClient-\>getIndex($company);

```
	$elasticaType = $elasticaIndex->getType($category);
	
	$researchDocument = new \Elastica\Document();
	$researchDocument->addFileContent('content', file_get_contents($path));
	
	// Add to type
	$elasticaType->addDocument($researchDocument);

	// Refresh Index
	$elasticaType->getIndex()->refresh();

```

Upon successful submit, I see one document inserted, and the content field is filled with a string of jibberish (JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGF) \<-- is a small paste of what is in the field I try to do a search on the type for the text that I know is in the PDF, but ES returns the message: curl: (52) Empty reply from server

I was under the impression that if I provided for those other fields, the attachment plugin would fill them in automatically.

Can anyone see something wrong in what I'm doing? I'm really stuck here.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:35am UTC](https://discuss.elastic.co/t/having-trouble-storing-attachments-what-am-i-doing-wrong/12021/3 "2017-07-06T02:35:49Z")

</div>


