Sorting on chardfields in Haystack and Elasticsearch
Current version on Haystack (2.10) combined with Elasticsearch produces weird results when you want to sort search results on charfield, the issue has been reported here https://github.com/toastdriven/django-haystack/issues/866" title="https://github.com/toastdriven/django-haystack/issues/866">https://github.com/toastdriven/django-haystack/issues/866 and here: https://github.com/toastdriven/django-haystack/issues/569" title="https://github.com/toastdriven/django-haystack/issues/569">https://github.com/toastdriven/django-haystack/issues/569 Long story short, to fix the problem you need to set indexed=False and stored=True on CharFields that you want to use for sorting. You should also set indexed=False on BooleanFields (if there are any in the search index model). Here's an example how the correct module would look like:
1 2 3 4 5 6
As you see above, we have created two fields for model_attr='title', first is regular, called title, the second one is sorted_name that is used for sorts. We also set Boolean 'active' as non-indexed, however it'll work for your search filters, it just won't get tokenized (yep, strange, but fact).