# Ingest attachment java ES

**URL:** <https://discuss.elastic.co/t/ingest-attachment-java-es/110351>\
**Category:** Elasticsearch\
**Created:** [December 5, 2017, 12:56pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351 "2017-12-05T12:56:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chelambarasan\_CR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chelambarasan_cr/32/62592_2.png) [@Chelambarasan\_CR](https://discuss.elastic.co/u/Chelambarasan_CR)\
**Post date:** [December 5, 2017, 12:56pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/1 "2017-12-05T12:56:49Z")

</div>

Hi ,

I am using ES 5.6.3 and a custom application to index the file system content.

In my index type, some fields needs to be stored as normal fields and file content needs to use ingest attachment pipeline.

```auto
PUT _ingest/pipeline/attachment { "description" : "Extract attachment information", "processors" : [{ "attachment" : { "field" : "content", "properties": [ "content", "title"] } } ] }

```

It means a record will have string fields as well as base64 binary fields from file system. The code is as below

```auto
 Map<String, String> emp = new HashMap<>();

String str1 = "test";
String str2 = Base64.getEncoder().encodeToString("parsed content".getBytes());

emp.add("meta", str1);
emp.add("content", str2);

IndexRequest ir = new IndexRequest("employee", "details", "1");

ir.source(emp).setPipeline("attachment");  

BulkRequestBuilder bulkBuilder = client.prepareBulk();
bulkBuilder.add(ir);		
BulkResponse bulkRes = bulkBuilder.execute().actionGet();

```

The record is not getting indexed.

I need both normal and binary field to be available in all records.

Please provide your suggestions

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 5, 2017, 2:00pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/2 "2017-12-05T14:00:47Z")

</div>

hey.

if you are using two hashmaps (emp1 and emp2) because those should be different entities, then you also need to have two different IndexRequests, one for each employee, and add both to your bulk request.

hope this helps.

--Alex

---

<div class="post-metadata">

**Author:** ![Chelambarasan\_CR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chelambarasan_cr/32/62592_2.png) [@Chelambarasan\_CR](https://discuss.elastic.co/u/Chelambarasan_CR)\
**Post date:** [December 5, 2017, 4:19pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/3 "2017-12-05T16:19:25Z")

</div>

Thanks for your reply. Both emp1 and emp2 are fields of same record with id1. Creating two index requests will replace the first record again.

---

<div class="post-metadata">

**Author:** ![Chelambarasan\_CR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chelambarasan_cr/32/62592_2.png) [@Chelambarasan\_CR](https://discuss.elastic.co/u/Chelambarasan_CR)\
**Post date:** [December 7, 2017, 6:27am UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/6 "2017-12-07T06:27:17Z")

</div>

@spinscale any help on this case?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 7, 2017, 7:53am UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/7 "2017-12-07T07:53:00Z")

</div>

This is a community forum and does not come with SLAs. Asking after one day of inactivity rather makes me stop to respond to a thread at all. If you need proper response times, there is commercial support.

You can only call `source()` once in your code, every new call overwrites the old one. You need to merge your data before that.

---

<div class="post-metadata">

**Author:** ![Chelambarasan\_CR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chelambarasan_cr/32/62592_2.png) [@Chelambarasan\_CR](https://discuss.elastic.co/u/Chelambarasan_CR)\
**Post date:** [December 7, 2017, 1:51pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/8 "2017-12-07T13:51:21Z")

</div>

Sorry bothering. Found the issue. Earlier in the index I have indexed it as normal content for the Id 1. When I tried to update the document with Id 1 as binary field for the content field. It was not updating the document. I indexed with document Id 2 and got indexed successfully.

This post can be closed.

---

<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:** [January 4, 2018, 1:52pm UTC](https://discuss.elastic.co/t/ingest-attachment-java-es/110351/9 "2018-01-04T13:52:21Z")

</div>

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