# Java.lang.OutOfMemoryError - how to anticipate memory usage?

**URL:** https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912
**Category:** Elasticsearch
**Created:** [November 18, 2011, 1:57pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912 "2011-11-18T13:57:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Michal\_Wegorek](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michal\_Wegorek](https://discuss.elastic.co/u/Michal_Wegorek)
#### Post date: [November 18, 2011, 1:57pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/1 "2011-11-18T13:57:25Z")

</div>

Problem:  
Indexing tens of millions of small (200B) docs. During indexing  
process memory is gradually rising, see:  
[![](http://i.imgur.com/xfI98.png) ](http://i.imgur.com/xfI98.png)

As soon as ES reaches max memory limit I receive WARN:  
failed engine java.lang.OutOfMemoryError: Java heap space

Since that moment, node is dead.

Questions:  
1)Is there any way to anticipate how much memory is needed if I want  
to store 5,000,000,000 docs?  
2)Why memory is gradually rising, is the memory usage rising together  
with number of docs?

My config:  
Using 1 index, default min/max memory limits.

cluster.name: mwegorekTest

gateway.type: fs  
gateway.fs.location: /mnt/mwegorek  
gateway.fs.snapshot\_interval: 30s  
gateway.recover\_after\_nodes: 2  
gateway.recover\_after\_time: 1m  
gateway.expected\_nodes: 4

discovery.zen.minimum\_master\_nodes: 2  
discovery.zen.ping.timeout: 3s  
discovery.zen.ping.multicast.enabled: false  
discovery.zen.ping.unicast.hosts: ["test-indexer-1.atm:9300", "test-  
indexer-2.atm:9300", "test-indexer-3.atm:9300", "test-indexer-4.atm:  
9300"]

threadpool:  
index:  
type: blocking  
min: 4  
size: 10  
wait\_time: 60s

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [November 20, 2011, 8:31am UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/2 "2011-11-20T08:31:45Z")

</div>

On Fri, Nov 18, 2011 at 3:57 PM, Michal Wegorek [wegorekm@gmail.com](mailto:wegorekm@gmail.com) wrote:

> Problem:  
> Indexing tens of millions of small (200B) docs. During indexing  
> process memory is gradually rising, see:  
> [http://i.imgur.com/xfI98.png](http://i.imgur.com/xfI98.png)
> 
> As soon as ES reaches max memory limit I receive WARN:  
> failed engine java.lang.OutOfMemoryError: Java heap space
> 
> Since that moment, node is dead.
> 
> Questions:  
> 1)Is there any way to anticipate how much memory is needed if I want  
> to store 5,000,000,000 docs?

Hard to tell without understanding the structure of the docs, what get  
indexed, and so on. You can extrapolate on the memory that will be needed  
by indexing a subset of the docs.

> 2)Why memory is gradually rising, is the memory usage rising together  
> with number of docs?

Yes, the more docs you have the more memory will be needed, but its not  
linear. Also, memory usage relates to if faceting are used, sorting, number  
of fields indexed, how the text get analyzed.

> My config:  
> Using 1 index, default min/max memory limits.
> 
> cluster.name: mwegorekTest
> 
> gateway.type: fs  
> gateway.fs.location: /mnt/mwegorek  
> gateway.fs.snapshot\_interval: 30s  
> gateway.recover\_after\_nodes: 2  
> gateway.recover\_after\_time: 1m  
> gateway.expected\_nodes: 4
> 
> discovery.zen.minimum\_master\_nodes: 2  
> discovery.zen.ping.timeout: 3s  
> discovery.zen.ping.multicast.enabled: false  
> discovery.zen.ping.unicast.hosts: ["test-indexer-1.atm:9300", "test-  
> indexer-2.atm:9300", "test-indexer-3.atm:9300", "test-indexer-4.atm:  
> 9300"]
> 
> threadpool:  
> index:  
> type: blocking  
> min: 4  
> size: 10  
> wait\_time: 60s

---

<div class="post-metadata">

### Author: ![Michal\_Wegorek](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michal\_Wegorek](https://discuss.elastic.co/u/Michal_Wegorek)
#### Post date: [November 21, 2011, 3:52pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/3 "2011-11-21T15:52:03Z")

</div>

Shay, thank you for a reply. Currently I'm preparing for  
extrapolation.

This is the record which is indexed(Python format):

data=r'''{"file" : {  
"id" : "000000000%d",  
"name" : "abc%d",  
"date" : "12.12.%d"  
}}'''

%d is starting as 0, then incremented

The data is indexed with simple pycurl HTTP PUT, no additional  
settings, all fields are indexed.

At around 1e+8 records 1024MB memory is not enough. Elasticsearch is  
raising java.lang.OutOfMemoryError.

Q1) Is elasticsearch caching index requests which cannot be served  
immediately by hard drive? Or is it done with a blocking way?

Q2) Is this the correct setting to make index behave in a blocking  
way?

threadpool:  
index:  
type: blocking

Q3) Memory is rasing together with number of records, you said its not  
linear, is it logarithmic?

ES version: 0.18.2

Best,  
Michal.

On 20 Lis, 09:31, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> On Fri, Nov 18, 2011 at 3:57 PM, Michal Wegorek [wegor...@gmail.com](mailto:wegor...@gmail.com) wrote:
> 
> > Problem:  
> > Indexing tens of millions of small (200B) docs. During indexing  
> > process memory is gradually rising, see:  
> > [http://i.imgur.com/xfI98.png](http://i.imgur.com/xfI98.png)
> 
> > As soon as ES reaches max memory limit I receive WARN:  
> > failed engine java.lang.OutOfMemoryError: Java heap space
> 
> > Since that moment, node is dead.
> 
> > Questions:  
> > 1)Is there any way to anticipate how much memory is needed if I want  
> > to store 5,000,000,000 docs?
> 
> Hard to tell without understanding the structure of the docs, what get  
> indexed, and so on. You can extrapolate on the memory that will be needed  
> by indexing a subset of the docs.
> 
> > 2)Why memory is gradually rising, is the memory usage rising together  
> > with number of docs?
> 
> Yes, the more docs you have the more memory will be needed, but its not  
> linear. Also, memory usage relates to if faceting are used, sorting, number  
> of fields indexed, how the text get analyzed.
> 
> > My config:  
> > Using 1 index, default min/max memory limits.
> 
> > cluster.name: mwegorekTest
> 
> > gateway.type: fs  
> > gateway.fs.location: /mnt/mwegorek  
> > gateway.fs.snapshot\_interval: 30s  
> > gateway.recover\_after\_nodes: 2  
> > gateway.recover\_after\_time: 1m  
> > gateway.expected\_nodes: 4
> 
> > discovery.zen.minimum\_master\_nodes: 2  
> > discovery.zen.ping.timeout: 3s  
> > discovery.zen.ping.multicast.enabled: false  
> > discovery.zen.ping.unicast.hosts: ["test-indexer-1.atm:9300", "test-  
> > indexer-2.atm:9300", "test-indexer-3.atm:9300", "test-indexer-4.atm:  
> > 9300"]
> 
> > threadpool:  
> > index:  
> > type: blocking  
> > min: 4  
> > size: 10  
> > wait\_time: 60s

---

<div class="post-metadata">

### Author: ![dungtc](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@dungtc](https://discuss.elastic.co/u/dungtc)
#### Post date: [November 21, 2011, 10:12pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/4 "2011-11-21T22:12:39Z")

</div>

Hello  
I use Java API to index 5 following documents into an index called javabulkindex and a mapping called javabulkmappingtype, using Java Bulk API with ES 0.18.4 and O.17.6:

BulkRequestBuilder BRB=client.prepareBulk();

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID1").setSource("field", JSONObject.fromObject(JsonString1)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID2").setSource("field", JSONObject.fromObject(JsonString2)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID3").setSource("field", JSONObject.fromObject(JsonString2)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID4").setSource("field", "value1"));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID5").setSource("field", "value2"));

BulkResponse br = BRB.execute().actionGet();

if (br.hasFailures()) {  
System.out.println("\nbulk failure with error: " + br.buildFailureMessage());

}

T

1. if this index and mapping ( javabulkindex and javabulkmappingtype) have been created before (with number\_of\_shards=7, numbers\_replicas=2), then all above commands have fails with error message "cannot allocate shards..."

2. if I delete this index and mapping and run these commands again, then:

- an index and mapping with these names are created  
-all first three commands are successful, but the two last commands fail with error message "try to parse string value as object but it seems that they are provided a value" and " a problem with EOF...". Attention: these last two commands I used String instead of an object for field's value.  
-if I delete first three commands, then these last two commands are successful.

So, please explain to me the reason and how to solve it.

Thanks a lot  
Tran CD

* * *

Ngu ngoc lon nhat cua doi nguoi la yeu duong - dieu ran thu 15 cua duc Phat (tai sao khong)

TINH YEU KHONG TU NHIEN SINH RA, KHONG TU NHIEN MAT DI, NO CHI CHUYEN TU NGUOI NAY SANG NGUOI KHAC

```
     NGAY MAI EM DI

```

BIEN NAM CHAN EM GIAT VE

* * *

De : Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)  
À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Envoyé le : Dimanche 20 Novembre 2011 9h31  
Objet : Re: java.lang.OutOfMemoryError - how to anticipate memory usage?

On Fri, Nov 18, 2011 at 3:57 PM, Michal Wegorek [wegorekm@gmail.com](mailto:wegorekm@gmail.com) wrote:

Problem:

> Indexing tens of millions of small (200B) docs. During indexing  
> process memory is gradually rising, see:  
> [http://i.imgur.com/xfI98.png](http://i.imgur.com/xfI98.png)
> 
> As soon as ES reaches max memory limit I receive WARN:  
> failed engine java.lang.OutOfMemoryError: Java heap space
> 
> Since that moment, node is dead.
> 
> Questions:  
> 1)Is there any way to anticipate how much memory is needed if I want  
> to store 5,000,000,000 docs?

Hard to tell without understanding the structure of the docs, what get indexed, and so on. You can extrapolate on the memory that will be needed by indexing a subset of the docs.

2)Why memory is gradually rising, is the memory usage rising together

> with number of docs?

Yes, the more docs you have the more memory will be needed, but its not linear. Also, memory usage relates to if faceting are used, sorting, number of fields indexed, how the text get analyzed.

> My config:  
> Using 1 index, default min/max memory limits.
> 
> cluster.name: mwegorekTest
> 
> gateway.type: fs  
> gateway.fs.location: /mnt/mwegorek  
> gateway.fs.snapshot\_interval: 30s  
> gateway.recover\_after\_nodes: 2  
> gateway.recover\_after\_time: 1m  
> gateway.expected\_nodes: 4
> 
> discovery.zen.minimum\_master\_nodes: 2  
> discovery.zen.ping.timeout: 3s  
> discovery.zen.ping.multicast.enabled: false  
> discovery.zen.ping.unicast.hosts: ["test-indexer-1.atm:9300", "test-  
> indexer-2.atm:9300", "test-indexer-3.atm:9300", "test-indexer-4.atm:  
> 9300"]
> 
> threadpool:  
> index:  
> type: blocking  
> min: 4  
> size: 10  
> wait\_time: 60s

---

<div class="post-metadata">

### Author: ![dungtc](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@dungtc](https://discuss.elastic.co/u/dungtc)
#### Post date: [November 21, 2011, 10:21pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/5 "2011-11-21T22:21:52Z")

</div>

Hello  
I re-send this question because I receive an error from my preceding sending, sorry to bother you.

I use Java API to index 5 following documents into an index called javabulkindex and a mapping called javabulkmappingtype, using Java Bulk API with ES 0.18.4 and O.17.6:

BulkRequestBuilder BRB=client.prepareBulk();

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID1").setSource("field", JSONObject.fromObject(JsonString1)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID2").setSource("field", JSONObject.fromObject(JsonString2)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID3").setSource("field", JSONObject.fromObject(JsonString2)));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID4").setSource("field", "value1"));

BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID5").setSource("field", "value2"));

BulkResponse br = BRB.execute().actionGet();

if (br.hasFailures()) {  
System.out.println("\nbulk failure with error: " + br.buildFailureMessage());

}

T

1. if this index and mapping ( javabulkindex and javabulkmappingtype) have been created before (with number\_of\_shards=7, numbers\_replicas=2), then all above commands have fails with error message "cannot allocate shards..."

2. if I delete this index and mapping and run these commands again, then:

- an index and mapping with these names are created  
-all first three commands are successful, but the two last commands fail with error message "try to parse string value as object but it seems that they are provided a value" and " a problem with EOF...". Attention: these last two commands I used String instead of an object for field's value.  
-if I delete first three commands, then these last two commands are successful.

So, please explain to me the reason and how to solve it. I really want to bulk documents into an available index and mapping that have been created before (problem 1) and to bulk successfully all these five commands (problem 2)

Thanks a lot  
Tran CD

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [November 22, 2011, 12:50pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/6 "2011-11-22T12:50:04Z")

</div>

How many nodes do you start? If you create an index with 2 replicas, and  
have just one data node you index into, it will not index into it, because  
not enough replicas are allocated (its expects a quorum to index).

Regarding your other problem, what is "field"? Is it a String, or a json  
object? It can't a String in some documents, and a json object / Map in  
other documents.

On Tue, Nov 22, 2011 at 12:21 AM, Chi Dung Tran [dungtctin4@yahoo.com](mailto:dungtctin4@yahoo.com)wrote:

> Hello  
> I re-send this question because I receive an error from my preceding  
> sending, sorry to bother you.
> 
> I use Java API to index 5 following documents into an index called javabulkindex  
> and a mapping called javabulkmappingtype, using Java Bulk API with ES  
> 0.18.4 and O.17.6:
> 
> BulkRequestBuilder BRB=client.prepareBulk();
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID1").setSource("field",  
> JSONObject.fromObject(JsonString1)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID2").setSource("field",  
> JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID3").setSource("field",  
> JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID4").setSource("field",  
> "value1"));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID5").setSource("field",  
> "value2"));
> 
> BulkResponse br = BRB.execute().actionGet();
> 
> if (br.hasFailures()) {  
> System.out.println("\nbulk failure with error: " +  
> br.buildFailureMessage());
> 
> }
> 
> T
> 
> 1. if this index and mapping ( javabulkindex and javabulkmappingtype)  
> have been created before (with number\_of\_shards=7, numbers\_replicas=2),  
> then all above commands have fails with error message "cannot allocate  
> shards..."
> 
> 2. if I delete this index and mapping and run these commands again, then:
> 
> - an index and mapping with these names are created  
> -all first three commands are successful, but the two last commands fail  
> with error message "try to parse string value as object but it seems that  
> they are provided a value" and " a problem with EOF...". Attention: these  
> last two commands I used String instead of an object for field's value.  
> -if I delete first three commands, then these last two commands are  
> successful.
> 
> So, please explain to me the reason and how to solve it. I really want to  
> bulk documents into an available index and mapping that have been created  
> before (problem 1) and to bulk successfully all these five commands  
> (problem 2)
> 
> Thanks a lot  
> Tran CD

---

<div class="post-metadata">

### Author: ![dungtc](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@dungtc](https://discuss.elastic.co/u/dungtc)
#### Post date: [November 23, 2011, 5:31pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/7 "2011-11-23T17:31:01Z")

</div>

Thanks for your response. All is tested on only one machine in my development box. There are two successfully createdindices : the first has has 9 shards, 2 replicas. The second has 7 shards, 3 replicas. If I index each document into one of two indices, it is always successful. If I use bulk, sometimes it fails with this error message "Failed to create shard, message [IndexShardCreationException... ,or :"UnavailableShardsException..." but sometimes it is successful when I restart the machine. In general, the failure only appears if I use bulks.  
So I cann't explain why.

* * *

Ngu ngoc lon nhat cua doi nguoi la yeu duong - dieu ran thu 15 cua duc Phat (tai sao khong)

TINH YEU KHONG TU NHIEN SINH RA, KHONG TU NHIEN MAT DI, NO CHI CHUYEN TU NGUOI NAY SANG NGUOI KHAC

```
     NGAY MAI EM DI

```

BIEN NAM CHAN EM GIAT VE

* * *

De : Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)  
À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Envoyé le : Mardi 22 Novembre 2011 13h50  
Objet : Re: JAVA Bulk API problems and failures

How many nodes do you start? If you create an index with 2 replicas, and have just one data node you index into, it will not index into it, because not enough replicas are allocated (its expects a quorum to index).

Regarding your other problem, what is "field"? Is it a String, or a json object? It can't a String in some documents, and a json object / Map in other documents.

On Tue, Nov 22, 2011 at 12:21 AM, Chi Dung Tran [dungtctin4@yahoo.com](mailto:dungtctin4@yahoo.com) wrote:

Hello

> I re-send this question because I receive an error from my preceding sending, sorry to bother you.
> 
> I use Java API to index 5 following documents into an index called javabulkindex and a mapping called javabulkmappingtype, using Java Bulk API with ES 0.18.4 and O.17.6:
> 
> BulkRequestBuilder BRB=client.prepareBulk();
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID1").setSource("field", JSONObject.fromObject(JsonString1)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID2").setSource("field",  
> JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID3").setSource("field", JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID4").setSource("field", "value1"));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID5").setSource("field", "value2"));
> 
> BulkResponse br = BRB.execute().actionGet();
> 
> if (br.hasFailures()) {T  
> System.out.println("\nbulk failure with error: " + br.buildFailureMessage());
> 
> }
> 
> T
> 
> 1. if this index and mapping ( javabulkindex and javabulkmappingtype) have been created before (with number\_of\_shards=7, numbers\_replicas=2), then all above commands have fails with error message "cannot allocate shards..."
> 
> 2. if I delete this index and mapping and run these commands again, then:
> 
> - an index and mapping with these names are created  
> -all first three commands are successful, but the two last commands fail with error message "try to parse string value as object but it seems that they are provided a value" and " a problem with EOF...". Attention: these last two commands I used String instead of an object for field's value.  
> -if I delete first three commands, then these last two commands are successful.
> 
> So, please explain to me the reason and how to solve it. I really want to bulk documents into an available index and mapping that have been created before (problem 1) and to bulk successfully all these five commands (problem 2)
> 
> Thanks a lot  
> Tran CD

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [November 24, 2011, 1:50pm UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/8 "2011-11-24T13:50:44Z")

</div>

If you start just one node, and create an index with 2 replicas, any  
indexing operation will fail because there isn't a quorum of shard replicas  
allocated (just 1, because you have 1 node). This is explained in the write  
consistency part in teh index operation:  
[Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/index_.html).

Here is an example:

# start one node, and create an index with 2 replicas

curl -XPUT localhost:9200/test1 -d '{  
"settings" : {  
"index.number\_of\_replicas" : 2  
}  
}'

# try and index a document, and see it fails (lower timeout to get fast

failure)  
curl -XPUT localhost:9200/test1/type1/1?timeout=10s -d '{}'

On Wed, Nov 23, 2011 at 7:31 PM, Chi Dung Tran [dungtctin4@yahoo.com](mailto:dungtctin4@yahoo.com) wrote:

> Thanks for your response. All is tested on only one machine in my  
> development box. There are two successfully created indices : the first  
> has has 9 shards, 2 replicas. The second has 7 shards, 3 replicas. If I  
> index each document into one of two indices, it is always successful. If I  
> use bulk, sometimes it fails with this error message "Failed to create  
> shard, message [IndexShardCreationException... ,or :"  
> UnavailableShardsException..." but sometimes it is successful when I  
> restart the machine. In general, the failure only appears if I use bulks.  
> So I cann't explain why.
> 
> - 
> 
> * * *
> 
> Ngu ngoc lon nhat cua doi nguoi la yeu duong - dieu ran thu 15 cua duc  
> Phat (tai sao khong)
> 
> TINH YEU KHONG TU NHIEN SINH RA, KHONG TU NHIEN MAT DI, NO CHI CHUYEN TU  
> NGUOI NAY SANG NGUOI KHAC
> 
> - 
> - 
> 
> ```
> NGAY MAI EM DI*
> 
> ```
> 
> _BIEN NAM CHAN EM GIAT VE_  
> \*\*
> 
> * * *
> 
> _De :_ Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)  
> _À :_ [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> _Envoyé le :_ Mardi 22 Novembre 2011 13h50  
> _Objet :_ Re: JAVA Bulk API problems and failures
> 
> How many nodes do you start? If you create an index with 2 replicas, and  
> have just one data node you index into, it will not index into it, because  
> not enough replicas are allocated (its expects a quorum to index).
> 
> Regarding your other problem, what is "field"? Is it a String, or a json  
> object? It can't a String in some documents, and a json object / Map in  
> other documents.
> 
> On Tue, Nov 22, 2011 at 12:21 AM, Chi Dung Tran [dungtctin4@yahoo.com](mailto:dungtctin4@yahoo.com)wrote:
> 
> Hello  
> I re-send this question because I receive an error from my preceding  
> sending, sorry to bother you.
> 
> I use Java API to index 5 following documents into an index called javabulkindex  
> and a mapping called javabulkmappingtype, using Java Bulk API with ES  
> 0.18.4 and O.17.6:
> 
> BulkRequestBuilder BRB=client.prepareBulk();
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID1").setSource("field",  
> JSONObject.fromObject(JsonString1)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID2").setSource("field",  
> JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID3").setSource("field",  
> JSONObject.fromObject(JsonString2)));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID4").setSource("field",  
> "value1"));
> 
> BRB.add(client.prepareIndex().setIndex("javabulkindex").setType("javabulkmappingtype").setId("ID5").setSource("field",  
> "value2"));
> 
> BulkResponse br = BRB.execute().actionGet();
> 
> if (br.hasFailures()) {T
> 
> ```
> System.out.println("\nbulk failure with error: " +
> 
> ```
> 
> br.buildFailureMessage());
> 
> }
> 
> T
> 
> 1. if this index and mapping ( javabulkindex and javabulkmappingtype)  
> have been created before (with number\_of\_shards=7, numbers\_replicas=2),  
> then all above commands have fails with error message "cannot allocate  
> shards..."
> 
> 2. if I delete this index and mapping and run these commands again, then:
> 
> - an index and mapping with these names are created  
> -all first three commands are successful, but the two last commands fail  
> with error message "try to parse string value as object but it seems that  
> they are provided a value" and " a problem with EOF...". Attention: these  
> last two commands I used String instead of an object for field's value.  
> -if I delete first three commands, then these last two commands are  
> successful.
> 
> So, please explain to me the reason and how to solve it. I really want to  
> bulk documents into an available index and mapping that have been created  
> before (problem 1) and to bulk successfully all these five commands  
> (problem 2)
> 
> Thanks a lot  
> Tran CD

---

<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, 3:47am UTC](https://discuss.elastic.co/t/java-lang-outofmemoryerror-how-to-anticipate-memory-usage/5912/9 "2017-07-06T03:47:38Z")

</div>


