Haystack front-end

[user]@[machine]:~/Development$ pip3 install django-haystack
Collecting django-haystack
  Downloading ...
  ...
Successfully installed django-haystack-2.8.1

Django settings

Add haystack to the INSTALLED_APPS in the Django project settings file.

(search) [user]@[machine]:~/Development/search/search$ vi settings.py
# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'haystack'
]

Define a back-end setting for haystack, in our case Elasticsearch in the same django settings.py file by adding the following code to it:

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

INDEX_NAME defines the default index name that we will store our data in and query our data from.

  • Last modified: 2020/03/25 17:24