Hi!
Since a stream is infinite, you cannot simply sort it (Flink does not follow the mini batch model). You can only sort in windows.
I assume you key by word and sum up the counts. Since you want to get the most frequent words, you would need to sort across keys, which you can do in a windowAll() function. Since you want a global sort, this will end up being a non-parallel step.
A more efficient variant is to have a bounded (N) max heap in the windowAll() function that you update with new elements and emit at the end. A fold() function should allow you to implement that.
BTW: It is probably also more efficient to parse the Strings into numbers once at the beginning of the program.
Stephan