August 2019
Intermediate to advanced
560 pages
13h 41m
English
By using the elasticsearch module to import the Elasticsearch class, we can initialize a low-level client with a hostname or address, a port, and parameters such as maximum connections, maxsize. The getInstance() method call returns the singleton client. With the following code block, you can obtain a low-level client running on the localhost with port=9200 and maxsize=25:
from elasticsearch import Elasticsearchclass ESLowLevelClient: __es = None __es_lock = threading.Lock() @staticmethod def get_instance(): if ESLowLevelClient.__es is None: with ESLowLevelClient.__es_lock: if ESLowLevelClient.__es is None: ESLowLevelClient.__es = Elasticsearch(['localhost'], port=9200, maxsize=25) return ESLowLevelClient.__es def ...
Read now
Unlock full access