Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Instantiate backend with proper host config

Jakub Draganeke23289fa8516
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.py
index c596fd66c9..bf676442e0 100644
--- a/saleor/search/backends/newelastic.py
+++ b/saleor/search/backends/newelastic.py
@@ -1,4 +1,5 @@
from elasticsearch import Elasticsearch
+from django.utils.six.moves.urllib.parse import urlparse
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import MultiMatch
@@ -13,11 +14,31 @@ def search(phrase):
return []
+def _get_es_hosts(params):
+ hosts = params.pop('HOSTS', None) or []
+ es_urls = params.pop('URLS', ['http://localhost:9200'])
+ for url in es_urls:
+ parsed_url = urlparse(url)
+ use_ssl = parsed_url.scheme == 'https'
+ port = parsed_url.port or (443 if use_ssl else 80)
+ http_auth = None
+ if parsed_url.username and parsed_url.password:
+ http_auth = (parsed_url.username, parsed_url.password)
+ hosts.append({
+ 'host': parsed_url.hostname,
+ 'port': port,
+ 'url_prefix': parsed_url.path,
+ 'use_ssl': use_ssl,
+ 'verify_certs': use_ssl,
+ 'http_auth': http_auth})
+ return hosts
+
+
class SearchBackend(object):
rebuilder_class = None
- def __init__(*args, **kwargs):
- pass
+ def __init__(self, params):
+ CLIENT = Elasticsearch(hosts=_get_es_hosts(params))
def search(self, query, model_or_queryset=None):
- pass
+ return []