# Java.lang.Double cannot be cast to org.apache.lucene.util.BytesRef

**URL:** https://discuss.elastic.co/t/java-lang-double-cannot-be-cast-to-org-apache-lucene-util-bytesref/27733
**Category:** Elasticsearch
**Created:** [August 20, 2015, 7:26am UTC](https://discuss.elastic.co/t/java-lang-double-cannot-be-cast-to-org-apache-lucene-util-bytesref/27733 "2015-08-20T07:26:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mahesh\_Bhat](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mahesh\_Bhat](https://discuss.elastic.co/u/Mahesh_Bhat)
#### Post date: [August 20, 2015, 7:26am UTC](https://discuss.elastic.co/t/java-lang-double-cannot-be-cast-to-org-apache-lucene-util-bytesref/27733/1 "2015-08-20T07:26:20Z")

</div>

hi !

I have an ELK system running for Log Analysis. I very recently used the "elapsed" filter plugin in logstash in order to track the time elapsed for the completion of a certain sequence of message events.

At times, I need to sort on the basis of the "elapsed.time" field in order to determine which events took too long for completion. Whenever a sort operation is carried out on this field, the search errors out with the following message :-

* * *

## [2015-08-20 06:35:30,105][DEBUG][action.search.type] [hostname\_client01] [logstash-2015.08.19][2]: Failed to exe cute [org.elasticsearch.action.search.SearchRequest@5bfa5386] while moving to second phase java.lang.ClassCastException: java.lang.Double cannot be cast to org.apache.lucene.util.BytesRef at org.apache.lucene.search.FieldComparator$TermOrdValComparator.compareValues(FieldComparator.java:902) at org.apache.lucene.search.TopDocs$MergeSortQueue.lessThan(TopDocs.java:172) at org.apache.lucene.search.TopDocs$MergeSortQueue.lessThan(TopDocs.java:120) at org.apache.lucene.util.PriorityQueue.upHeap(PriorityQueue.java:225) at org.apache.lucene.util.PriorityQueue.add(PriorityQueue.java:133) at org.apache.lucene.search.TopDocs.merge(TopDocs.java:234) at org.elasticsearch.search.controller.SearchPhaseController.sortDocs(SearchPhaseController.java:239) at ......... at .........

Here is a sample of the message containing the "elapsed.time" field :-

* * *

{  
"\_index": "logstash-2015.08.19",  
"\_type": "abc\_eventforwarder",  
"\_id": "AU9DYWvkrr\_mxpPid7mz",  
"\_score": 1,  
"\_source": {  
"message": "INFO 2015-08-19 00:34:59,977 enrichment\_processor on\_delivery\_confirmation 239 : Received ack for delivery tag: 4719",  
"@version": "1",  
"@timestamp": "2015-08-19T00:34:59.977Z",  
"type": "abc\_eventforwarder",  
"host": "hostname",  
"path": "/var/log/eventforwarder/enrichment\_processor.log",  
"tags": [  
"\_grokparsefailure",  
"endlag\_flag",  
"elapsed",  
"elapsed.match"  
],  
"mtype": "INFO",  
"mesgid": "4719",  
"elapsed.time": 0.582,  
"elapsed.timestamp\_start": "2015-08-19T00:34:59.482Z"  
},  
"fields": {  
"elapsed.timestamp\_start": [  
1439944499482  
],  
"@timestamp": [  
1439944499977  
]  
}  
}

* * *

I am using Elasticsearch version - 1.6.1

Any ideas on why I see that error ?

Thanks !

- mahesh.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [August 21, 2015, 3:30pm UTC](https://discuss.elastic.co/t/java-lang-double-cannot-be-cast-to-org-apache-lucene-util-bytesref/27733/2 "2015-08-21T15:30:14Z")

</div>

What likely happened is that you ran a terms aggregation across several indices, and the field was mapped as a double on one index and as a double on another index. We just merged a change that returns a clearer error message in that case.

---

<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 5, 2017, 11:54pm UTC](https://discuss.elastic.co/t/java-lang-double-cannot-be-cast-to-org-apache-lucene-util-bytesref/27733/3 "2017-07-05T23:54:33Z")

</div>


