improve elastic server settings
This commit is contained in:
@@ -4,15 +4,28 @@ from elasticsearch_dsl import Search, Q
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pillar import current_app
|
from pillar import current_app
|
||||||
|
|
||||||
client = Elasticsearch()
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
node_agg_terms = ['node_type', 'media', 'tags', 'is_free']
|
node_agg_terms = ['node_type', 'media', 'tags', 'is_free']
|
||||||
user_agg_terms = ['roles', ]
|
user_agg_terms = ['roles', ]
|
||||||
|
|
||||||
|
|
||||||
|
class TheELKClient():
|
||||||
|
"""
|
||||||
|
current_app is not available when on import
|
||||||
|
"""
|
||||||
|
client: Elasticsearch = None
|
||||||
|
|
||||||
|
def get_client(self):
|
||||||
|
if not self.client:
|
||||||
|
self.client = Elasticsearch(
|
||||||
|
current_app.config['ELASTIC_SEARCH_HOSTS'])
|
||||||
|
else:
|
||||||
|
return self.client
|
||||||
|
|
||||||
|
elk = TheELKClient()
|
||||||
|
|
||||||
|
|
||||||
def add_aggs_to_search(search, agg_terms):
|
def add_aggs_to_search(search, agg_terms):
|
||||||
"""
|
"""
|
||||||
Add facets / aggregations to the search result
|
Add facets / aggregations to the search result
|
||||||
@@ -42,7 +55,7 @@ def nested_bool(must: list, should: list, terms: dict) -> Search:
|
|||||||
must.append(bool_query)
|
must.append(bool_query)
|
||||||
bool_query = Q('bool', must=must)
|
bool_query = Q('bool', must=must)
|
||||||
|
|
||||||
search = Search(using=client)
|
search = Search(using=elk.get_client())
|
||||||
search.query = bool_query
|
search.query = bool_query
|
||||||
|
|
||||||
return search
|
return search
|
||||||
@@ -129,7 +142,7 @@ def do_user_search_admin(query: str) -> dict:
|
|||||||
Q('match', full_name=query),
|
Q('match', full_name=query),
|
||||||
]
|
]
|
||||||
bool_query = Q('bool', should=should)
|
bool_query = Q('bool', should=should)
|
||||||
search = Search(using=client)
|
search = Search(using=elk.get_client())
|
||||||
search.query = bool_query
|
search.query = bool_query
|
||||||
|
|
||||||
if log.isEnabledFor(logging.DEBUG):
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
@@ -80,7 +80,7 @@ ALGOLIA_INDEX_NODES = 'dev_Nodes'
|
|||||||
|
|
||||||
SEARCH_BACKENDS = ('algolia', 'elastic') # search backend we use
|
SEARCH_BACKENDS = ('algolia', 'elastic') # search backend we use
|
||||||
|
|
||||||
ELASTIC_SEARCH_HOSTS = ['elasticsearch'] # elasticsearch hosts
|
|
||||||
ELASTIC_INDICES = {
|
ELASTIC_INDICES = {
|
||||||
# elasticsearch indexes
|
# elasticsearch indexes
|
||||||
'NODE': 'nodes',
|
'NODE': 'nodes',
|
||||||
@@ -88,6 +88,29 @@ ELASTIC_INDICES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_docker_host():
|
||||||
|
"""
|
||||||
|
Looks for the DOCKER_HOST environment variable to find the VM
|
||||||
|
running docker-machine.
|
||||||
|
|
||||||
|
If the environment variable is not found, it is assumed that
|
||||||
|
you're running docker on localhost.
|
||||||
|
"""
|
||||||
|
d_host = os.getenv('DOCKER_HOST', None)
|
||||||
|
if d_host:
|
||||||
|
if re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', d_host):
|
||||||
|
return d_host
|
||||||
|
|
||||||
|
return re.match(r'tcp://(.*?):\d+', d_host).group(1)
|
||||||
|
return 'localhost'
|
||||||
|
|
||||||
|
|
||||||
|
# Elasticsearch hosts
|
||||||
|
ELASTIC_SEARCH_HOSTS = ["{}:{}".format(
|
||||||
|
os.getenv('ELASTICSEARCH_PORT_9200_TCP_ADDR', get_docker_host()),
|
||||||
|
os.getenv('ELASTICSEARCH_PORT_9200_TCP_PORT', 9200))]
|
||||||
|
|
||||||
|
|
||||||
ZENCODER_API_KEY = '-SECRET-'
|
ZENCODER_API_KEY = '-SECRET-'
|
||||||
ZENCODER_NOTIFICATIONS_SECRET = '-SECRET-'
|
ZENCODER_NOTIFICATIONS_SECRET = '-SECRET-'
|
||||||
ZENCODER_NOTIFICATIONS_URL = 'http://zencoderfetcher/'
|
ZENCODER_NOTIFICATIONS_URL = 'http://zencoderfetcher/'
|
||||||
|
Reference in New Issue
Block a user