# Index\_out\_of\_bounds\_exception: null

**URL:** <https://discuss.elastic.co/t/index-out-of-bounds-exception-null/164467>\
**Category:** Elasticsearch\
**Created:** [January 16, 2019, 12:45pm UTC](https://discuss.elastic.co/t/index-out-of-bounds-exception-null/164467 "2019-01-16T12:45:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vipul\_tyagi](https://avatars.discourse-cdn.com/v4/letter/v/c37758/32.png) [@vipul\_tyagi](https://discuss.elastic.co/u/vipul_tyagi)\
**Post date:** [January 16, 2019, 12:45pm UTC](https://discuss.elastic.co/t/index-out-of-bounds-exception-null/164467/1 "2019-01-16T12:45:24Z")

</div>

I am running below Query :-

GET /index\_prod\_v2\*/\_search  
{  
"size": 0,  
"query": {  
"bool": {  
"must": [  
{  
"range":{  
"time": {  
"gte": "2018-11-01T02:30:00.000Z",  
"lte": "2018-11-02T05:30:01.000Z"  
}  
}  
}  
]  
}  
},  
"aggs": {  
"Level1\_groupByCompetitor": {  
"composite": {  
"size": 1000,  
"sources": [  
{  
"fieldName1": {  
"terms": {  
"field": "fieldName1"  
}  
}  
},  
{  
"fieldName2": {  
"terms": {  
"field":"fieldName2"  
}  
}  
}  
]  
},  
"aggs": {  
"distinct\_count": {  
"scripted\_metric": {  
"init\_script": """  
params.\_agg.map = [:];  
""",  
"map\_script": """  
if (!params.\_agg.map.containsKey(doc.fieldName3.value)) {  
params.\_agg.map[doc['sku'].value] = 1;  
}  
""",  
"reduce\_script": """  
def reduce = [:];  
for (agg in params.\_aggs) {  
for (entry in agg.map.entrySet()) {  
if (!reduce.containsKey(entry.getKey())) {  
reduce[entry.getKey()] = entry.getValue();  
}  
}  
}  
return reduce.size();  
"""  
}  
}  
}  
}  
}  
}

which is throwing below error :-

{  
"took": 998,  
"timed\_out": false,  
"\_shards": {  
"total": 3568,  
"successful": 3567,  
"skipped": 3560,  
"failed": 1,  
"failures": [  
{  
"shard": 0,  
"index": "index\_prod\_v2\_y2018\_w44\_m11\_d1",  
"node": "Siz6c8KYROyrnaHpqhTRRg",  
"reason": {  
"type": "script\_exception",  
"reason": "runtime error",  
"script\_stack": [  
"java.nio.Buffer.checkIndex(Buffer.java:546)",  
"java.nio.DirectByteBuffer.getShort(DirectByteBuffer.java:594)",  
"org.apache.lucene.store.ByteBufferGuard.getShort(ByteBufferGuard.java:123)",  
"org.apache.lucene.store.ByteBufferIndexInput$SingleBufferImpl.readShort(ByteBufferIndexInput.java:400)",  
"org.apache.lucene.util.packed.DirectReader$DirectPackedReader16.get(DirectReader.java:185)",  
"org.apache.lucene.codecs.lucene70.Lucene70DocValuesProducer$19.ordValue(Lucene70DocValuesProducer.java:865)",  
"org.apache.lucene.index.SingletonSortedSetDocValues.advanceExact(SingletonSortedSetDocValues.java:83)",  
"org.elasticsearch.index.fielddata.FieldData$10.advanceExact(FieldData.java:423)",  
"org.elasticsearch.index.fielddata.ScriptDocValues$BinaryScriptDocValues.setNextDocId(ScriptDocValues.java:520)",  
"org.elasticsearch.index.fielddata.ScriptDocValues$Strings.setNextDocId(ScriptDocValues.java:555)",  
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",  
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",  
"params.\_agg.map[doc['field3'].value] = 1; \n }",  
" ^---- HERE"  
],  
"script": """  
if (!params.\_agg.map.containsKey('doc.field3.value')) {  
params.\_agg.map[doc['field3'].value] = 1;  
}  
""",  
"lang": "painless",  
"caused\_by": {  
"type": "index\_out\_of\_bounds\_exception",  
"reason": "index\_out\_of\_bounds\_exception: null"  
}  
}  
}  
]  
},  
"hits": {  
"total": 145639,  
"max\_score": 0,  
"hits":   
},  
"aggregations": {  
"Level1\_groupByCompetitor": {  
"buckets": [  
{  
"key": {  
"field1": "360Buy",  
"field2": 3240  
},  
"doc\_count": 487,  
"distinct\_count": {  
"value": 394  
}  
},  
{  
"key": {  
"field1": "360Buy",  
"field2": 3240  
},  
"doc\_count": 763,  
"distinct\_count": {  
"value": 606  
}  
},  
}

The Same query works with terms aggregation while it fails with composite Aggregation. Elastic Search Version is 6.5

---

<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:** [February 13, 2019, 12:45pm UTC](https://discuss.elastic.co/t/index-out-of-bounds-exception-null/164467/2 "2019-02-13T12:45:25Z")

</div>

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