# Getting Exception while running Aggregation Queries

**URL:** https://discuss.elastic.co/t/getting-exception-while-running-aggregation-queries/43507
**Category:** Elasticsearch
**Created:** [March 4, 2016, 12:43pm UTC](https://discuss.elastic.co/t/getting-exception-while-running-aggregation-queries/43507 "2016-03-04T12:43:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![moni15moni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moni15moni/32/42311_2.png) [@moni15moni](https://discuss.elastic.co/u/moni15moni)
#### Post date: [March 4, 2016, 12:43pm UTC](https://discuss.elastic.co/t/getting-exception-while-running-aggregation-queries/43507/1 "2016-03-04T12:43:12Z")

</div>

Hi

I am getting the following exception in es 2.1.0 java api migration.

Failed to execute phase [query], all shards failed; shardFailures {[YGPc1Z8\_QYektQpNh-C9rQ][fw3][0]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][1]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][2]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][3]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][4]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }  
Failed to execute phase [query], all shards failed; shardFailures {[YGPc1Z8\_QYektQpNh-C9rQ][fw3][0]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][1]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][2]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][3]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }{[YGPc1Z8\_QYektQpNh-C9rQ][fw3][4]: RemoteTransportException[[10.2.1.50][10.2.1.50:9302][indices:data/read/search[phase/query/id]]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]]; }  
at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.onQueryFailure(TransportSearchDfsQueryThenFetchAction.java:139)  
at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$1.onFailure(TransportSearchDfsQueryThenFetchAction.java:120)  
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)  
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:821)  
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:799)  
at org.elasticsearch.transport.TransportService$4.onFailure(TransportService.java:361)  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:42)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: NotSerializableExceptionWrapper[Expected numeric type on field [first\_occurance], but got [string]]; nested: IllegalArgumentException[Expected numeric type on field [first\_occurance], but got [string]];  
at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:382)

What is wrong with the below query,While executing thiso ne i am getting the above exception,Can anyone help this.

{  
"size" : 100,  
"query" : {  
"bool" : {  
"filter" : [ {  
"match\_all" : { }  
}, {  
"bool" : {  
"must" : {  
"range" : {  
"first\_occurance" : {  
"from" : 1456790400000,  
"to" : 1456876799000,  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}  
}  
} ]  
}  
},  
"aggregations" : {  
"date" : {  
"date\_histogram" : {  
"field" : "first\_occurance",  
"interval" : "1d",  
"format" : "yyyy-MM-dd HH:mm:ss"  
}  
}  
}  
}

Thanks  
Moni

---

<div class="post-metadata">

### Author: ![byronvoorbach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byronvoorbach/32/8283_2.png) [@byronvoorbach](https://discuss.elastic.co/u/byronvoorbach)
#### Post date: [March 4, 2016, 1:34pm UTC](https://discuss.elastic.co/t/getting-exception-while-running-aggregation-queries/43507/2 "2016-03-04T13:34:42Z")

</div>

Hi Moni,

The following part of the stack trace shows your issue:

`Expected numeric type on field [first_occurance], but got [string]`.

This indicates that there is probably something wrong with your mapping. Could you post the mapping for your `first_occurance` field? (you can find you mapping by calling this url: http://{host}:{ip}/{index}/\_mapping).  
It will probably show that your `first_occurance` field is of type `String`, if that's the case you need to recreate your index with a mapping of type `Date` in order to get the required functionality.

Hope this helps.

Kind regards,

Byron

---

<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:11pm UTC](https://discuss.elastic.co/t/getting-exception-while-running-aggregation-queries/43507/3 "2017-07-05T23:11:15Z")

</div>


