`ops_keys` never changes, so it should be a constant defined once in the global scope, instead of each time this function is called. Also, you're defining a hash which is unordered, and sorting it each time, which is wasteful. You could instead just have an array of arrays and avoid resorting:

```
OPTS_KEYS = [
      ['date_happened', 'd'],
      ['hostname', 'h'],
      ['aggregation_key', 'k'],
      ['priority', 'p'],
      ['source_type_name', 's'],
      ['alert_type', 't']
]
```