# OutOfMemory insexing documents

**URL:** <https://discuss.elastic.co/t/outofmemory-insexing-documents/8227>\
**Category:** Elasticsearch\
**Created:** [June 26, 2012, 12:28pm UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227 "2012-06-26T12:28:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tullio0106](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tullio0106](https://discuss.elastic.co/u/tullio0106)\
**Post date:** [June 26, 2012, 12:28pm UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227/1 "2012-06-26T12:28:34Z")

</div>

I'm trying to index 4000 documents, however I allways get an  
OutOfMemory exception.  
My simple code is a loop around :  
public void indicizzaDocumento(String xpIndice, InputStream  
xpContent, HashMap\<String,Object\> xpParametri) throws IOException {  
HashMap\<String,Object\> mappa = (HashMap\<String, Object\>)  
xpParametri.clone();  
long inizio = new Date().getTime();  
byte[] contiene = IOUtils.toByteArray(xpContent);  
String contenuto = new String(JsonUtils.encode(contiene));  
mappa.put(CONTENUTO, contenuto);  
StringWriter sw = new StringWriter();  
mapper.writeValue(sw, mappa);  
String json = sw.getBuffer().toString();

client.prepareIndex(INDICE,TIPO,xpIndice).setSource(json).execute().actionGet();  
long gap = new Date().getTime() - inizio;  
System.out.println("millis for "+xpIndice+" "+gap);  
}

What's wrong ?  
I tried to profile the code with no relevant informations.  
Tks  
Tullio

---

<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:** [June 26, 2012, 2:25pm UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227/2 "2012-06-26T14:25:18Z")

</div>

How big is a single doc? Do you start elasticsearch with any specific  
settings?

On Tue, Jun 26, 2012 at 2:28 PM, tullio0106 [tbettinazzi@axioma.it](mailto:tbettinazzi@axioma.it) wrote:

> I'm trying to index 4000 documents, however I allways get an  
> OutOfMemory exception.  
> My simple code is a loop around :  
> public void indicizzaDocumento(String xpIndice, InputStream  
> xpContent, HashMap\<String,Object\> xpParametri) throws IOException {  
> HashMap\<String,Object\> mappa = (HashMap\<String, Object\>)  
> xpParametri.clone();  
> long inizio = new Date().getTime();  
> byte contiene = IOUtils.toByteArray(xpContent);  
> String contenuto = new String(JsonUtils.encode(contiene));  
> mappa.put(CONTENUTO, contenuto);  
> StringWriter sw = new StringWriter();  
> mapper.writeValue(sw, mappa);  
> String json = sw.getBuffer().toString();
> 
> client.prepareIndex(INDICE,TIPO,xpIndice).setSource(json).execute().actionGet();  
> long gap = new Date().getTime() - inizio;  
> System.out.println("millis for "+xpIndice+" "+gap);  
> }
> 
> What's wrong ?  
> I tried to profile the code with no relevant informations.  
> Tks  
> Tullio

---

<div class="post-metadata">

**Author:** ![tullio0106](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tullio0106](https://discuss.elastic.co/u/tullio0106)\
**Post date:** [June 26, 2012, 4:17pm UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227/3 "2012-06-26T16:17:38Z")

</div>

The size is more or less 1Mb each (mean).  
Noting relevant I believe:  
. shards 5  
. replicas 1  
. type local  
. index.mapping.attachment.indexed\_chars -1  
Tks  
Tullio

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [June 28, 2012, 1:55am UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227/4 "2012-06-28T01:55:25Z")

</div>

Tullio,

Try increasing your -Xmx parameter.

You may want to get SPM ( [Sematext Monitoring | Infrastructure Monitoring Service](http://sematext.com/spm/index.html) ) so you can  
visually see the size of your JVM heap and JVM Garbage Collection, among  
other things.

## Otis

Search Analytics - [Cloud Monitoring Tools & Services | Sematext](http://sematext.com/search-analytics/index.html)  
Scalable Performance Monitoring - [Sematext Monitoring | Infrastructure Monitoring Service](http://sematext.com/spm/index.html)

On Tuesday, June 26, 2012 12:17:39 PM UTC-4, tullio0106 wrote:

> The size is more or less 1Mb each (mean).  
> Noting relevant I believe:  
> . shards 5  
> . replicas 1  
> . type local  
> . index.mapping.attachment.indexed\_chars -1  
> Tks  
> Tullio
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/OutOfMemory-insexing-documents-tp4019764p4019774.html](http://elasticsearch-users.115913.n3.nabble.com/OutOfMemory-insexing-documents-tp4019764p4019774.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:22am UTC](https://discuss.elastic.co/t/outofmemory-insexing-documents/8227/5 "2017-07-06T03:22:18Z")

</div>


