Merged from upstream

This pull request merges all changes from upstream (elasticsearch). Fixes sorting problem!