Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Integrating elasticsearch connection pooling in Django

I have a django application that stores status info of lots of sensors and I'm trying to use elasticsearch to store all of the status data, for further analysis.

I have used elasticsearch a lot in Python scripts in general.

My question is how to integrate elasticsearch-py/elasticsearch-dsl connection pooling into a django application. I would like to not create a connection for every request. I'm actually trying to embeed it into MyAppConfig inside apps.py but I'm not sure if it's a good idea.

Any help?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Elasticsearch-dsl can be integrated easily using the ready app function in the following way.

/init.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)

then in django settings I have a dictionary called elasticsearch with alias configurations

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
            }
        ]
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!