Replace OpenSearch with Elasticsearch
This commit is contained in:
@@ -217,7 +217,7 @@ class StorageBackend(object):
|
||||
# For every hit from ES
|
||||
for index, item in enumerate(list(response["hits"]["hits"])):
|
||||
# For every blacklisted type
|
||||
for blacklisted_type in settings.OPENSEARCH_BLACKLISTED.keys():
|
||||
for blacklisted_type in settings.ELASTICSEARCH_BLACKLISTED.keys():
|
||||
# Check this field we are matching exists
|
||||
if "_source" in item.keys():
|
||||
data_index = "_source"
|
||||
@@ -228,7 +228,7 @@ class StorageBackend(object):
|
||||
if blacklisted_type in item[data_index].keys():
|
||||
content = item[data_index][blacklisted_type]
|
||||
# For every item in the blacklisted array for the type
|
||||
for blacklisted_item in settings.OPENSEARCH_BLACKLISTED[
|
||||
for blacklisted_item in settings.ELASTICSEARCH_BLACKLISTED[
|
||||
blacklisted_type
|
||||
]:
|
||||
if blacklisted_item == str(content):
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -7,9 +7,9 @@ def get_db():
|
||||
|
||||
return DruidBackend()
|
||||
elif settings.DB_BACKEND == "ELASTICSEARCH":
|
||||
from core.db.elastic import ElasticSearchBackend
|
||||
from core.db.elastic import ElasticsearchBackend
|
||||
|
||||
return OpensearchBackend()
|
||||
return ElasticsearchBackend()
|
||||
elif settings.DB_BACKEND == "MANTICORE":
|
||||
from core.db.manticore import ManticoreBackend
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from math import ceil
|
||||
from django.conf import settings
|
||||
from numpy import array_split
|
||||
|
||||
from core.db.opensearch import client, run_main_query
|
||||
from core.db.elastic import client, run_main_query
|
||||
|
||||
|
||||
def construct_query(net, nicks):
|
||||
@@ -48,7 +48,7 @@ def get_meta(request, net, nicks, iter=True):
|
||||
request.user,
|
||||
query,
|
||||
custom_query=True,
|
||||
index=settings.OPENSEARCH_INDEX_META,
|
||||
index=settings.ELASTICSEARCH_INDEX_META,
|
||||
)
|
||||
if "hits" in results.keys():
|
||||
if "hits" in results["hits"]:
|
||||
|
||||
Reference in New Issue
Block a user