Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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
            }
        ]
    }
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda