fix: es使用https报错

pull/13415/head
wangruidong 6 months ago committed by 老广
parent 3608b025e5
commit 0a0312695b

@ -16,7 +16,7 @@ from django.utils.translation import gettext_lazy as _
from django.db.models import QuerySet as DJQuerySet
from elasticsearch7 import Elasticsearch
from elasticsearch7.helpers import bulk
from elasticsearch7.exceptions import RequestError
from elasticsearch7.exceptions import RequestError, SSLError
from elasticsearch7.exceptions import NotFoundError as NotFoundError7
from elasticsearch8.exceptions import NotFoundError as NotFoundError8
@ -40,11 +40,16 @@ class NotSupportElasticsearch8(JMSException):
default_detail = _('Not Support Elasticsearch8')
class InvalidElasticsearchSSL(JMSException):
default_code = 'invalid_elasticsearch_SSL'
default_detail = _(
'Connection failed: Self-signed certificate used. Please check server certificate configuration')
class ESClient(object):
def __new__(cls, *args, **kwargs):
hosts = kwargs.get('hosts', [])
version = get_es_client_version(hosts=hosts)
version = get_es_client_version(**kwargs)
if version == 6:
return ESClientV6(*args, **kwargs)
if version == 7:
@ -95,11 +100,16 @@ class ESClientV8(ESClientBase):
return {field: {'order': direction}}
def get_es_client_version(hosts, **kwargs):
es = Elasticsearch(hosts=hosts, max_retries=0, **kwargs)
def get_es_client_version(**kwargs):
try:
es = Elasticsearch(**kwargs)
info = es.info()
version = int(info['version']['number'].split('.')[0])
return version
except SSLError:
raise InvalidElasticsearchSSL
except Exception:
raise InvalidElasticsearch
class ES(object):

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e4baadc170ded5134bed55533c4c04e694be6ea7b8e151d80c1092728e26a75b
size 177500
oid sha256:4c47b806817e09e63c804277a1a2db8bdf959807e482605322be323922c38209
size 177735

File diff suppressed because it is too large Load Diff

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:08667579241592ecacd1baf330147a720a9e41171444b925f90778613a7e1d9a
size 145230
oid sha256:d83f99f39e0052ea2592a3f5bb4be56a94be0963436b45031083891c44a44ba0
size 145454

File diff suppressed because it is too large Load Diff

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:93fed3f6a027f645520852f40c5f7722a5be579a3a8bb7b7029e3d0bc9794056
size 145341
oid sha256:9021dd51a99b425416105a1e2a5b7b63f6725dec2de3b124a0520e4e1a09003f
size 145565

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save