Elasticsearch-dsl可以通過以下方式輕鬆使用就緒應用程序功能進行集成。
/初始化的.py
default_app_config = '<app>.apps.AppConfig'
/apps.py
import logging
from django.apps import AppConfig
from django.conf import settings
from elasticsearch_dsl.connections import connections
log = logging.getLogger('elastic')
class AppConfig(AppConfig):
name = <app_name>
def ready(self):
connections.configure(**settings.ELASTICSEARCH)
在Django設置
然後我有一個名爲elasticsearch與別名配置字典
ELASTICSEARCH = {
'default': {
'hosts': [
{
'host': <your_host>,
'port': <your_host_port>,
'verify_certs': True,
'use_ssl': True,
'http_auth': (
<auth_name>,
<auth_passwd>
)
}
]
},
'dev': {
'hosts': [
{
'host': 'localhost',
'port': 9200
}
]
}
}