Issue with Elasticsearch 1.7.0 queries with Java 8 Update 66 on Mac

I have a use case where i am trying to fetch some data from elasticsearch in sorted order , below is the java code to do so.

QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("id", id)).must(QueryBuilders.matchQuery("status", status)).must(QueryBuilders.rangeQuery("requestedTimestamp").gte(d.getTime()));

Iterable values = userOnlineOtpRepository.search(queryBuilder, new PageRequest(0, CommonConstants.ES_PAGINATION_LIMIT, new Sort(new Sort.Order(Sort.Direction.DESC, "requestedTimestamp"))));

This query always throws error , but works if i remove the portion which sorts the data i.e new Sort(new Sort.Order(Sort.Direction.DESC, "requestedTimestamp")).

My Elasticsearch is running on local mac machine with Java 8 Update 66. Is it the Java version which is causing error ?

Providing the error you got would be helpful :slight_smile:

This is the error log..

Failed to execute phase [dfs], all shards failed; shardFailures {[Yb2FXnm2QimOmPqUgbbLJg][otpindex][0]: SearchParseException[[otpindex][0]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [Failed to parse source [{"from":0,"size":1,"query":{"bool":{"must":[{"match":{"userId":{"query":"5456765189","type":"boolean"}}},{"range":{"requestedTimestamp":{"from":1456992127734,"to":null,"include_lower":true,"include_upper":true}}}]}},"sort":[{"requestedTimestamp":{"order":"desc"}}]}]]]; nested: SearchParseException[[otpindex][0]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [No mapping found for [requestedTimestamp] in order to sort on]]; }{[Yb2FXnm2QimOmPqUgbbLJg][otpindex][1]: SearchParseException[[otpindex][1]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [Failed to parse source [{"from":0,"size":1,"query":{"bool":{"must":[{"match":{"userId":{"query":"5456765189","type":"boolean"}}},{"range":{"requestedTimestamp":{"from":1456992127734,"to":null,"include_lower":true,"include_upper":true}}}]}},"sort":[{"requestedTimestamp":{"order":"desc"}}]}]]]; nested: SearchParseException[[otpindex][1]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [No mapping found for [requestedTimestamp] in order to sort on]]; }{[Yb2FXnm2QimOmPqUgbbLJg][otpindex][2]: SearchParseException[[otpindex][2]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [Failed to parse source [{"from":0,"size":1,"query":{"bool":{"must":[{"match":{"userId":{"query":"5456765189","type":"boolean"}}},{"range":{"requestedTimestamp":{"from":1456992127734,"to":null,"include_lower":true,"include_upper":true}}}]}},"sort":[{"requestedTimestamp":{"order":"desc"}}]}]]]; nested: SearchParseException[[otpindex][2]: query[+userId:5456765189 +requestedTimestamp:[1456992127734 TO *]],from[0],size[1]: Parse Failure [No mapping found for [requestedTimestamp] in order to sort on]]; }

Already an entry exist which contains a mapping for requestedTimestamp.

What does the mapping look like then?

localhost:9200
GET /otpindex/_mapping

{
"otpindex": {
"mappings": {
"UserOnlineOtp": {
"properties": {
"clientId": {
"type": "string"
},
"id": {
"type": "string",
"index": "not_analyzed"
},
"otp": {
"type": "string"
},
"phone": {
"type": "string"
},
"requestedTimestamp": {
"type": "long"
},
"status": {
"type": "string"
},
"userId": {
"type": "long"
}
}
}
}
}
}

Above is the search result from Sense. It has got mapping field for "requestedTimestamp" , but it still throws error while sorting on this field.

Above stuff works fine if the Java version is 7 .

Right, but it's mapped a timestamp as a long, not an actual date. I think you need to fix your mappings.

We are facing same issue if we use "userId": {"type": "long"} as the sort parameter in ES query.