title: Facing memory issues with elastic search while indexing
body: <p>I have 3 nodes(aws elasticsearch service)  of 16GB running for elastic search service. I have configured my ES to have 3 shards with 2 replicas. These 3 nodes are responsible for indexing of data and querying and fetching of data. </p>
  
  <p>Heap Allocation for all 3 is 7GB. </p>
  
  <p>Data is split into 2 indices, index1 and index2. Index1 does not have much data and the document sizes are small. Index2 is the heavier index but the max document size in that too is 1MB. </p>
  
  <p>However, many times while indexing some documents for index2, one of the ES instance throws OutOfMemoryException. I checked shards memory and there are total of 3.5 GB of document data in index2. </p>
  
  <p>I am unable to figure out the cause for this and looking for some help in debugging the issue.</p>
  
  <p>The structure of the document is similar to : </p>
  
  <pre><code>    {  
          "name":"ABC",
          "class":10,
          "school":"XYZ",
          "subjects":[  
                 {  
                    "A":{  
                    "name":"subject a",
                    "marks":80,
                    "passed":true
                    }
                 },
                 {  
                   "B":{  
                     "name":"subject B",
                     "marks":76,
                     "passed":true
                 }
              }
          ]
        }
  </code></pre>
  
  <p>The array in "subjects" key can go upto a length of 3000.</p>
  
  <p>The ES version being used is 5.1.0.</p>
  
  <p>Find the stack trace below : </p>
  
  <pre><code>[2017-07-28T15:44:13,912][WARN ][o.e.m.j.JvmGcMonitorService] [obLzpwI] [gc][849973] overhead, spent [26s] collecting in the last [26.1s]
  [2017-07-28T15:44:13,895][WARN ][o.e.t.n.Netty4Transport  ] [obLzpwI] exception caught on transport layer [[!!!io.netty.channel.socket.nio.NioSocketChannel@650b7925=&gt;java.lang.OutOfMemoryError:Compressed class space!!!]], closing connection
  org.elasticsearch.ElasticsearchException: java.lang.OutOfMemoryError: Compressed class space
      at org.elasticsearch.transport.netty4.Netty4Transport.exceptionCaught(Netty4Transport.java:326) [transport-netty4-5.1.2.jar:5.1.2]
      at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.exceptionCaught(Netty4MessageChannelHandler.java:84) [transport-netty4-5.1.2.jar:5.1.2]
      at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:296) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:861) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:375) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:280) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:396) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:536) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:490) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
      at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) [netty-common-4.1.6.Final.jar:4.1.6.Final]
      at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
  Caused by: java.lang.OutOfMemoryError: Compressed class space
  </code></pre>