Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting on timestamp inconsistent in 3.1 #1733

Closed
matthughes opened this issue Oct 22, 2014 · 8 comments
Closed

Sorting on timestamp inconsistent in 3.1 #1733

matthughes opened this issue Oct 22, 2014 · 8 comments

Comments

@matthughes
Copy link

Here is my mapping for:

"@timestamp" : {
"format" : "dateOptionalTime",
"type" : "date"
},

If I instruct Kibana to sort newest to oldest, the results seem to come in completely random order. If I use the curl query Kibana gives and look at the JSON results, they are sorted in the correct order, newest to oldest.

@rashidkpc
Copy link
Contributor

I've not been able to duplicate this in Kibana 3.1, however all development has moved to Kibana 4. Are you seeing this issue in master?

@matthughes
Copy link
Author

I have not tried v4 yet. Looking at the code though, I have a question:

from table/module.js

          // Sort the data
          $scope.data = _.sortBy($scope.data, function(v){
            if(!_.isUndefined(v.sort)) {
              return v.sort[0];
            } else {
              return v._score;
            }
          });

          // Reverse if needed
          if($scope.panel.sort[1] === 'desc') {
            $scope.data.reverse();
          }

Why does Kibana sort this data again? The JSON is already sorted and in the correct order AFAICT. Besides being an expensive operation, this -- in my case and others judging by the the number of timestamp issues reported -- is causing incorrect sorting.

@rashidkpc
Copy link
Contributor

The resorting is necessary for the sequential querying we do. We query one index at a time, and need to resort the results once they hit Kibana. Its possible if you have any indexes in which @timestamp is not a date that the sort order could appear incorrect.

@matthughes
Copy link
Author

Interesting. I can only see one search query getting posted to /_search/_all.

I did a bit more digging and was hoping to find this return surprising results:

_.sortBy([1,2,3], function(v) { return null });

As that is what is happening in my case, but it does not appear to disturb the original order when returning null.

@rashidkpc
Copy link
Contributor

If you point kibana at a specific instead of _all does the problem continue to occur?

@matthughes
Copy link
Author

I'm back to blaming elasticsearch. I have a daily index with an alias for those indicies. Mapping for the timestamp field is the same on all. Looking at the results again, Kibana isn't the problem. The sort value is wrong:

0: "2014-10-24T16:27:25.180Z 1414168045180"
1: "2014-10-24T16:27:25.180Z 1414168045180"
2: "2014-10-24T16:27:29.450Z 1414168049450"
3: "2014-10-24T16:27:28.372Z 1414168048372"
4: "2014-10-24T16:27:28.372Z 1414168048372"

For each hit, i printed out the timestamp and the sort array. I didn't think there should even be a sort value but apparently there is. As you can see the sort order doesn't make sense. If I just target an individual index instead of the alias, it works fine.

Seems to be related to elastic/elasticsearch#7343 but I haven't confirmed that yet.

@rashidkpc
Copy link
Contributor

gotcha, I'll go ahead and close this.

@matthughes
Copy link
Author

FYI: I wrote up the real issue here: elastic/elasticsearch#8226

It appears that if you have an empty index, it affects sort order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants