def connect_pool(): pool = Transport([{ "host": "localhost", "port": 9200 }], connection_class=RequestsHttpConnection).connection_pool conn = pool.get_connection() return conn
def connect(cls, conn_name, **kwargs): config = kwargs or settings.ES[conn_name] conn = Transport(config['nodes'], connection_class=RequestsHttpConnection, sniff_on_start=True, sniff_on_connection_fail=True, retry_on_timeout=True, **config) cls._pool[conn_name] = conn.connection_pool
from elasticsearch.helpers import bulk, reindex, scan, streaming_bulk es = Elasticsearch( [{ "host": "localhost", "port": 9443 }], transport_class=Transport, ) t = Transport( [{}], connection_class=RequestsHttpConnection, connection_pool_class=ConnectionPool, sniff_on_start=True, sniffer_timeout=0.1, sniff_timeout=1, sniff_on_connection_fail=False, max_retries=1, retry_on_status={100, 400, 503}, retry_on_timeout=True, send_get_body_as="source", ) def sync_gen() -> Generator[Dict[Any, Any], None, None]: yield {} def scan_types() -> None: for _ in scan( es,
# -*- coding: utf-8 -*- import random import requests from elasticsearch import Transport from elasticsearch.connection import RequestsHttpConnection from config.base_config import ES_HOSTS, ES_INDEX, ES_CONNECTION_NUM hosts = [] for host in ES_HOSTS: hosts.append({'url': host}) connection_pool = Transport( hosts, connection_class=RequestsHttpConnection).connection_pool def get_es_conn(): return connection_pool.get_connection() def search(query): con = get_es_conn() status, headers, data = con.perform_request( 'GET', '/' + ES_INDEX + '/_search?q=' + query) return data # ----------------------------------------------------- import json from es_client import search query_str = "((title:*" + keyword + "*)OR(key_words:*" + keyword + "*))AND(is_public:true)AND(publish_time:[0 TO " + str(
def get_write_transport(self, **kwargs): if not self.write_transport: self.write_transport = Transport(self.w_host, **kwargs) return self.write_transport
def get_read_transport(self, **kwargs): if not self.read_transport: r_host = self.r_host if len( self.r_host) > 1 else self.r_host * self.max_r_trans self.read_transport = Transport(r_host, **kwargs) return self.read_transport