Search code examples
elasticsearchdjango-haystack

Haystack and elasticsearch not working with one character


I am trying to make searches using haystack and elasticsearch but for some reason it only returns results when I search a word with more than one character.

How do I enable one character searches?

This is my index

class CustomerIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    first_name_auto = indexes.CharField(model_attr='first_name', default='')
    last_name_auto = indexes.CharField(model_attr='last_name', default='')
    full_name_auto = indexes.EdgeNgramField(model_attr='get_full_name', default='')
    address1 = indexes.CharField(model_attr='address1', indexed=False,
                                 default='')
    accounts_customer_auto = indexes.MultiValueField()

    def get_model(self):
        return Customer

    def prepare_accounts_customer_auto(self, obj):
        return [a.id for a in obj.accounts.all()]

    # def index_queryset(self, using=None):
    #     """Used when the entire index for model is updated."""
    #     return Customer.objects.all()

    def get_model(self):
        return Customer

and this is the query

sqs = SearchQuerySet().filter(
                full_name_auto__exact=query_text).order_by('-full_name_auto').models(Customer)

Solution

  • This seems to be an haystack default feature