Problem sorting a field descendingly with SearchRequestBuilder

Hi, I am having a problem using the SearchRequestBuilder to sort a
field descendingly.

I have some documents mapped with:

{
"network" : {
"properties" : {
"n_cpes": {
"type": "multi_field",
"fields": {
"n_cpes": {
"type": "long",
"index" : "analyzed"
},
"raw": {
"type": "long",
"index": "not_analyzed"
}
}
},
"n_accesses": {
"type": "multi_field",
"fields": {
"n_accesses": {
"type": "long",
"index" : "analyzed"
},
"raw": {
"type": "long",
"index": "not_analyzed"
}
}
}
}
}
}

I have no problems sorting the n_accesses field but when I try to order the
n_cpes, ES returns an unordered list!

The thing is, when I curl ES to sort the n_cpes field with a JSON similar
to the one built with SearchRequestBuilder the result is the expected one.

Here is how I use the SearchRequestBuilder (the query is built client-side
and so i use the extraSource method add the query):

SearchRequestBuilder requestBuilder = client.prepareSearch(indexes.toArray(
new String[indexes.size()]))
.setTypes(new String[]{type})
.setFrom(from)
.setSize(size);

if (sortField != null) {
requestBuilder.addSort(prepareSorter(sortField, sortAscending));
}

if (jsFilter != null && jsFilter.length() > 0) {
requestBuilder.setFilter(prepareFilterExpression(jsFilter));
}

try {
requestBuilder.setExtraSource(query.toString().getBytes("UTF-8"));

} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("We cannot continue without UTF-8", e);
}

SearchResponse response = requestBuilder.execute().actionGet();

return new JSONObject(response.toString());

The prepareSorter method looks like this:

SortOrder order = ascending ? SortOrder.ASC : SortOrder.DESC;

return new FieldSortBuilder(field + ".raw")
.order(order)
.ignoreUnmapped(true);

Am I doing something wrong?

I would appreciate some help!

Thanks!

João Félix

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.