AutoFill doesn't work with EdgeNgramField using haystack and Elasticsearch engine (Django)

I need to find the substring values ​​in the model field. I have an Index and SearchQuerySet.

This is an Elasticsearch configuration.

HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 'URL': 'http://127.0.0.1:9200/', 'INDEX_NAME': 'haystack', }, } 

My index.

 class ElementIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #model fields title_element = indexes.EdgeNgramField(model_attr='title') clean_content = indexes.EdgeNgramField(model_attr='clean_content') def get_model(self): return Element def index_queryset(self, using=None): """Used when the entire index for model is updated.""" return Element.objects.filter(updatetime__lte=datetime.datetime.now()) 

My custom search.

 SearchQuerySet().filter(title_element=clean_value) 

I have the value "HolaMundoTest" in my database, and if I try to search for "Hola" or "HolaM", I will find the result, but if I try "Mundo" or "mundo" or "laMun", there are no matches.

What's wrong? I do not understand.

source http://django-haystack.readthedocs.org/en/v2.1.0/autocomplete.html

I use:

  • -django 1.5.1
  • -django-stack == 2.1.0
  • -elasticsearch-0.90.5
  • -pyelasticsearch == 0.6

Thank you for your responses -

+6
source share
1 answer

Since you are using EdgeNgramField, which is the expected behavior, as it tokens by spaces and matches texts starting with characters in the request.

To get results for the query "laMun" or "mundo", you should use NgramField instead of EdgeNgramField.

+4
source

Source: https://habr.com/ru/post/956579/


All Articles