Add opensearch library
This commit is contained in:
parent
d9ee13cb14
commit
7c53e0ec9d
|
@ -0,0 +1,39 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from opensearchpy import OpenSearch
|
||||||
|
|
||||||
|
|
||||||
|
def initialise_opensearch():
|
||||||
|
auth = (settings.OPENSEARCH_USERNAME, settings.OPENSEARCH_PASSWORD)
|
||||||
|
client = OpenSearch(
|
||||||
|
hosts=[{"host": settings.OPENSEARCH_URL,
|
||||||
|
"port": settings.OPENSEARCH_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,
|
||||||
|
verify_certs=False,
|
||||||
|
ssl_assert_hostname=False,
|
||||||
|
ssl_show_warn=False,
|
||||||
|
# a_certs=ca_certs_path,
|
||||||
|
)
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
def construct_query(query):
|
||||||
|
query = {
|
||||||
|
"size": 5,
|
||||||
|
"query": {
|
||||||
|
"multi_match": {
|
||||||
|
"query": query,
|
||||||
|
"fields": settings.OPENSEARCH_MAIN_SEARCH_FIELDS,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
def run_main_query(client, query):
|
||||||
|
search_query = construct_query(query)
|
||||||
|
response = client.search(body=search_query, index=settings.OPENSEARCH_INDEX_MAIN)
|
||||||
|
return response
|
Loading…
Reference in New Issue