Replace OpenSearch with Elasticsearch
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
# from datetime import datetime, timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from opensearchpy import OpenSearch
|
||||
from opensearchpy.exceptions import NotFoundError, RequestError
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch.exceptions import NotFoundError, RequestError
|
||||
|
||||
from core.db import StorageBackend
|
||||
|
||||
@@ -19,18 +19,18 @@ class ElasticsearchBackend(StorageBackend):
|
||||
|
||||
def initialise(self, **kwargs):
|
||||
"""
|
||||
Inititialise the OpenSearch API endpoint.
|
||||
Inititialise the Elastuicsearch API endpoint.
|
||||
"""
|
||||
auth = (settings.OPENSEARCH_USERNAME, settings.OPENSEARCH_PASSWORD)
|
||||
client = OpenSearch(
|
||||
auth = (settings.ELASTICSEARCH_USERNAME, settings.ELASTICSEARCH_PASSWORD)
|
||||
client = Elasticsearch(
|
||||
# fmt: off
|
||||
hosts=[{"host": settings.OPENSEARCH_URL,
|
||||
"port": settings.OPENSEARCH_PORT}],
|
||||
hosts=[{"host": settings.ELASTICSEARCH_URL,
|
||||
"port": settings.ELASTICSEARCH_PORT}],
|
||||
http_compress=False, # enables gzip compression for request bodies
|
||||
http_auth=auth,
|
||||
# client_cert = client_cert_path,
|
||||
# client_key = client_key_path,
|
||||
use_ssl=settings.OPENSEARCH_TLS,
|
||||
use_ssl=settings.ELASTICSEARCH_TLS,
|
||||
verify_certs=False,
|
||||
ssl_assert_hostname=False,
|
||||
ssl_show_warn=False,
|
||||
@@ -40,7 +40,7 @@ class ElasticsearchBackend(StorageBackend):
|
||||
|
||||
def construct_query(self, query, size, use_query_string=True, tokens=False):
|
||||
"""
|
||||
Accept some query parameters and construct an OpenSearch query.
|
||||
Accept some query parameters and construct an Elasticsearch query.
|
||||
"""
|
||||
if not size:
|
||||
size = 5
|
||||
@@ -116,10 +116,10 @@ class ElasticsearchBackend(StorageBackend):
|
||||
try:
|
||||
response = client.search(body=search_query, index=index)
|
||||
except RequestError as err:
|
||||
print("OpenSearch error", err)
|
||||
print("Elasticsearch error", err)
|
||||
return err
|
||||
except NotFoundError as err:
|
||||
print("OpenSearch error", err)
|
||||
print("Elasticsearch error", err)
|
||||
return err
|
||||
return response
|
||||
|
||||
@@ -137,7 +137,7 @@ class ElasticsearchBackend(StorageBackend):
|
||||
tags=None,
|
||||
):
|
||||
"""
|
||||
API helper to alter the OpenSearch return format into something
|
||||
API helper to alter the Elasticsearch return format into something
|
||||
a bit better to parse.
|
||||
Accept a HTTP request object. Run the query, and annotate the
|
||||
results with the other data we have.
|
||||
|
||||
Reference in New Issue
Block a user