# Attachments from ECM to Elastic Search using Java API

**URL:** <https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505>\
**Category:** Elasticsearch\
**Created:** [February 25, 2017, 10:44pm UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505 "2017-02-25T22:44:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PARAG\_BHAGWAT](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@PARAG\_BHAGWAT](https://discuss.elastic.co/u/PARAG_BHAGWAT)\
**Post date:** [February 25, 2017, 10:44pm UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505/1 "2017-02-25T22:44:45Z")

</div>

Hello,

I have done basic indexing in Elastic search using the JAVA api. I am using Elastic Search 5.1.1. I am really new to this so sorry if this is a basic question but this is what i am trying to do

1. I installed the ingest-attachment plugin using the command tool
2. We have an attachment storage for now lets assume i can read document in bytes or have access to the location where tthe document is stored like c:\temp\transactionid.pdf

The question is now how do i tie all of this together? How do i use the Java transport client and Index API (PUT) to submit this attachment to an index named attachment\_index so it becomes searchable?

Thanks in advance.

Thanks,

---

<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 25, 2017, 11:06pm UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505/2 "2017-02-25T23:06:17Z")

</div>

You need to first create a pipeline which uses ingest-attachment processor.  
Then simply index a document as usual but with a pipeline. In this document, encode the binary content into BASE64 and add this to a field of your doc.

FYI you can also look at FSCrawler project in case it can help.

---

<div class="post-metadata">

**Author:** ![PARAG\_BHAGWAT](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@PARAG\_BHAGWAT](https://discuss.elastic.co/u/PARAG_BHAGWAT)\
**Post date:** [February 25, 2017, 11:58pm UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505/3 "2017-02-25T23:58:27Z")

</div>

Thanks David. I will take a look at FSCrawler. Where i am getting stuck is calling the pipeline through Java. Here's what i have done till now

I created an mapping as given in documentation through the Kibana developer kit.

PUT \_ingest/pipeline/ecm\_attachment  
{  
"description" : "Extract attachment information",  
"processors" : [  
{  
"attachment" : {  
"field" : "data"  
}  
}  
]  
}

Now i want to use this pipeline in my Java client during my client.prepareIndex call. Is there a way to specify which pipeline to use as well when sending the data? I will be using Apache commons BASE64 encoder to encode the file.

[https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#encodeBase64(byte[])](https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#encodeBase64(byte%5B%5D))

Thanks,  
Parag Bhagwat

---

<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 26, 2017, 12:13am UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505/4 "2017-02-26T00:13:54Z")

</div>

From the top of my head it should be something like:

```
client.prepareIndex(...).source(json).pipeline("pipeline")
```

---

<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:** [March 26, 2017, 12:14am UTC](https://discuss.elastic.co/t/attachments-from-ecm-to-elastic-search-using-java-api/76505/5 "2017-03-26T00:14:08Z")

</div>

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