forked from gsingers/search_with_machine_learning_course
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopensearch.py
28 lines (23 loc) · 1.03 KB
/
opensearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask import g, current_app
from opensearchpy import OpenSearch
# Create an OpenSearch client instance and put it into Flask shared space for use by the application
def get_opensearch():
if 'opensearch' not in g:
# Implement a client connection to OpenSearch so that the rest of the application can communicate with OpenSearch
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
# Create the client with SSL/TLS enabled, but hostname and certificate verification disabled.
client = OpenSearch(
hosts=[{'host': host, 'port': port}],
http_compress=True, # enables gzip compression for request bodies
http_auth=auth,
# client_cert = client_cert_path,
# client_key = client_key_path,
use_ssl=True,
verify_certs=False,
ssl_assert_hostname=False,
ssl_show_warn=False,
)
g.opensearch = client
return g.opensearch