# Bulk update with java API

**URL:** https://discuss.elastic.co/t/bulk-update-with-java-api/25398
**Category:** Elasticsearch
**Created:** [July 12, 2015, 8:44pm UTC](https://discuss.elastic.co/t/bulk-update-with-java-api/25398 "2015-07-12T20:44:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)
#### Post date: [July 12, 2015, 8:44pm UTC](https://discuss.elastic.co/t/bulk-update-with-java-api/25398/1 "2015-07-12T20:44:46Z")

</div>

Hi.

So I'm trying to index multiple documents using Bulk API in java.

My documents are valid (I checked if I can index them one by one - and it works).

The bulk API also works - partially, because from 169 documents, only 3 are indexed. Ids of my documents are unique.  
This is how I'm building BulkProcessor:

```
BulkProcessor.builder(client, new BulkProcessor.Listener() {
		@Override
		public void beforeBulk(long executionId, BulkRequest request) {
		}

		@Override
		public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
		}

		@Override
		public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
		}
	}).setBulkActions(2000)
          .setBulkSize(new ByteSizeValue(500, ByteSizeUnit.MB))
          .setFlushInterval(TimeValue.timeValueMinutes(5))
          .setConcurrentRequests(1).build();

```

And this is how I add my documents to bulkProcessor:

```
bulkProcessor.add(indexRequest(indexName).type(INDEX_TYPE).source(
					XContentFactory.jsonBuilder().map(data)));

```

What I'm doing step by step:

1. Check if index with given name exists
2. If it is, remove it
3. Create new index
4. Wait for cluster green status
5. Create BulkProcessor
6. Add indexRequests to bulkProcessor
7. Close BulkProcessor
8. Wait for Cluster green status
9. Send refresh request
10. Remove index with alias "indexaliasName"
11. Add indexAliasName to index which was created in point number 3.

Any ideas what can be the reason of adding only three documents? Instead of 160 ?

---

<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: [July 12, 2015, 9:06pm UTC](https://discuss.elastic.co/t/bulk-update-with-java-api/25398/2 "2015-07-12T21:06:30Z")

</div>

I'd trace results in both afterBulk methods to check what is happening.

---

<div class="post-metadata">

### Author: ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)
#### Post date: [July 12, 2015, 9:40pm UTC](https://discuss.elastic.co/t/bulk-update-with-java-api/25398/3 "2015-07-12T21:40:12Z")

</div>

Ehh, sorry for bothering. I did very terrible mistake.

My Models which I used were not new objects, so in fact I had a list of three modeles repeated many times.

Everything works now when I'm creating new Object per document of course..

---

<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, 12:01am UTC](https://discuss.elastic.co/t/bulk-update-with-java-api/25398/4 "2017-07-06T00:01:59Z")

</div>


