# How to index an attachment with Java API

**URL:** <https://discuss.elastic.co/t/how-to-index-an-attachment-with-java-api/10778>\
**Category:** Elasticsearch\
**Created:** [February 18, 2013, 3:49pm UTC](https://discuss.elastic.co/t/how-to-index-an-attachment-with-java-api/10778 "2013-02-18T15:49:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yann\_Moisan](https://avatars.discourse-cdn.com/v4/letter/y/3d9bf3/32.png) [@Yann\_Moisan](https://discuss.elastic.co/u/Yann_Moisan)\
**Post date:** [February 18, 2013, 3:49pm UTC](https://discuss.elastic.co/t/how-to-index-an-attachment-with-java-api/10778/1 "2013-02-18T15:49:32Z")

</div>

Hi,

I need to index a document with an attachment, using the Java API.

Is it the good method IndexRequestBuilder.setSource(byte[] source) ?  
(Javadoc is'nt very verbose ...)

If yes, do i need to encode in base 64 ?

Is there an example somewhere ?

I read about SimpleAttachmentIntegrationTests but don't find it in the  
source code (0.20.5) ...

Thx for help,  
Yann.

--  
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:** [February 18, 2013, 4:00pm UTC](https://discuss.elastic.co/t/how-to-index-an-attachment-with-java-api/10778/2 "2013-02-18T16:00:12Z")

</div>

Hey Yann,

Have a look here: [https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/servlet/UploadServlet.java#L100](https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/servlet/UploadServlet.java#L100)

It should help.

Let me know if you need more explanation.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 18 févr. 2013 à 16:49, Yann Moisan [yamo93@gmail.com](mailto:yamo93@gmail.com) a écrit :

> Hi,
> 
> I need to index a document with an attachment, using the Java API.
> 
> Is it the good method IndexRequestBuilder.setSource(byte source) ? (Javadoc is'nt very verbose ...)
> 
> If yes, do i need to encode in base 64 ?
> 
> Is there an example somewhere ?
> 
> I read about SimpleAttachmentIntegrationTests but don't find it in the source code (0.20.5) ...
> 
> Thx for help,  
> Yann.
> 
> --  
> 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:50am UTC](https://discuss.elastic.co/t/how-to-index-an-attachment-with-java-api/10778/3 "2017-07-06T02:50:55Z")

</div>

Closed on July 6, 2017, 2:50am UTC


