Getting Exception while running Aggregation Queries

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

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