Sorting across nodes

Hi,

I'm querying with a sort clause, and I'm getting unexpected results. I'm using the java client.

I'm sorting by a long timestamp field. The generated sort clause looks like this:
"sort" : [ {
"timestamp_ms" : {
"order" : "desc"
}
} ]

The main issue is that I'm getting five separate sorted groupings. There are five nodes in my cluster, so it would seem it is sorting per node, but that's just a guess.

A secondary issue is that it's sorting ascending, not descending.

Here is a sample of the results I am getting (timestamp formatted to a string for readability). After this block, there are four more similar sets of results, starting over at Oct 1.

How can I get es fully sort this result set?

Thu Oct 01 19:02:32 EDT 2015
Thu Oct 01 19:36:48 EDT 2015
Thu Oct 01 19:38:26 EDT 2015
Thu Oct 01 20:41:22 EDT 2015
Fri Oct 02 09:18:57 EDT 2015
Fri Oct 02 09:29:10 EDT 2015
Fri Oct 02 20:34:34 EDT 2015
Fri Oct 02 21:57:42 EDT 2015
Fri Oct 02 22:25:10 EDT 2015
Sat Oct 03 07:21:38 EDT 2015
Sun Oct 04 00:35:19 EDT 2015
Sun Oct 04 00:06:13 EDT 2015
Sun Oct 04 00:09:46 EDT 2015
Sun Oct 04 07:46:56 EDT 2015
Sun Oct 04 07:49:50 EDT 2015
Sun Oct 04 08:04:05 EDT 2015
Sun Oct 04 10:49:27 EDT 2015
Mon Oct 05 19:48:57 EDT 2015
Mon Oct 05 19:57:09 EDT 2015
Mon Oct 05 20:57:11 EDT 2015
Mon Oct 05 21:01:48 EDT 2015
Mon Oct 05 21:02:19 EDT 2015
Mon Oct 05 21:57:19 EDT 2015
Tue Oct 06 07:38:36 EDT 2015
Tue Oct 06 07:37:40 EDT 2015
Tue Oct 06 07:39:39 EDT 2015
Tue Oct 06 11:03:07 EDT 2015
Tue Oct 06 19:16:55 EDT 2015
Tue Oct 06 19:19:32 EDT 2015
Tue Oct 06 19:59:04 EDT 2015
Tue Oct 06 20:01:21 EDT 2015
Tue Oct 06 23:13:54 EDT 2015
Wed Oct 07 12:19:11 EDT 2015
Wed Oct 07 21:14:01 EDT 2015
Thu Oct 08 12:47:59 EDT 2015

If you use Sense or curl and just do, are you getting the same results?

GET /yourindex/_search
{
  "size": 200, 
  "fields": ["timestamp_ms"], 
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "timestamp_ms": {
        "order": "desc"
      }
    }
  ]
}

Hi,

Thanks for the response. It seems to only be an issue through the Java client. Is there some trick to getting it to work?

I appreciate any help.

-Adam

Hi,

I'm not sure, you can post your code here or link it to a gist and maybe we can figure out whats wrong.

I've developed a lot of code around querying elasticsearch, but the sort part boils down to something like this:
searchRequestBuilder.addSort("field_name", SortOrder.DESC);

And I see the sort clause in the query.

I tried this, but it didn't help:
searchRequestBuilder.setSearchType("dfs_query_and_fetch");

The code to get the values looks something like this:

            SearchResponse response = searchRequestBuilder.get();
	SearchHits hits = response.getHits();
	for (SearchHit hit : hits) {
		Map<String, SearchHitField> hitFields = hit.fields();
		for (Entry<String, SearchHitField> entry : hitFields.entrySet()) {
			List<Object> values = entry.getValue().getValues();
			if (values != null && values.size() > 0) {
				String key = entry.getKey().toString();
				for (Object value : values) {
                                    // etc...

There was a bug in my code. Thanks for looking though.