Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 13 additions & 31 deletions complaint_search/es_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from urllib.parse import quote

from flags.state import flag_enabled
from opensearchpy import OpenSearch, RequestsHttpConnection, helpers
from requests_aws4auth import AWS4Auth
from opensearchpy import OpenSearch, helpers

from complaint_search.defaults import (
CSV_ORDERED_HEADERS,
Expand Down Expand Up @@ -36,11 +35,6 @@
_ES_PASSWORD = os.environ.get("ES_PASSWORD", "")
_ES_INSTANCE = None

USE_AWS_ES = os.environ.get("USE_AWS_ES", False)
AWS_ES_ACCESS_KEY = os.environ.get("AWS_ES_ACCESS_KEY")
AWS_ES_SECRET_KEY = os.environ.get("AWS_ES_SECRET_KEY")
AWS_ES_HOST = os.environ.get("ES_HOST")

_COMPLAINT_ES_INDEX = os.environ.get("COMPLAINT_ES_INDEX", "complaint-index")


Expand Down Expand Up @@ -144,30 +138,18 @@ def process_trends_response(response):
def _get_es():
global _ES_INSTANCE
if _ES_INSTANCE is None:
if USE_AWS_ES: # pragma: no cover
awsauth = AWS4Auth(
AWS_ES_ACCESS_KEY, AWS_ES_SECRET_KEY, "us-east-1", "es"
)
_ES_INSTANCE = OpenSearch(
hosts=[{"host": AWS_ES_HOST, "port": 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection,
timeout=100,
)
else:
host = _ES_HOST
if _ES_USER and _ES_PASSWORD:
encoded_username = quote(_ES_USER)
encoded_password = quote(_ES_PASSWORD)
host = f"{encoded_username}:{encoded_password}@{host}"

_ES_INSTANCE = OpenSearch(
f"http://{host}:{_ES_PORT}",
use_ssl=(str(_ES_PORT) == "443"),
timeout=100
)
host = _ES_HOST
if _ES_USER and _ES_PASSWORD:
encoded_username = quote(_ES_USER)
encoded_password = quote(_ES_PASSWORD)
host = f"{encoded_username}:{encoded_password}@{host}"

_ES_INSTANCE = OpenSearch(
f"http://{host}:{_ES_PORT}",
use_ssl=(str(_ES_PORT) == "443"),
timeout=100,
pool_maxsize=10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to add an ES_POOL_MAXSIZE environment variable that defaults to 10?

@wpears wpears Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That certainly would have been a nice, tunable thing :)

)
return _ES_INSTANCE


Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ def get_git_version():
"opensearch-py>=2.1.0,<=3.0.0",
"django-localflavor>=4.0,<5.0",
"django-flags>=5",
"requests-aws4auth",
]

testing_extras = [
"coverage>=7.4,<8",
"deep==0.10",
"deepdiff>=6.7,<7",
"parameterized==0.9.0",
"requests-aws4auth",
]


Expand Down
Loading