From c9c2e5caa5e251bb554c36eac554baead87d7833 Mon Sep 17 00:00:00 2001 From: babebe Date: Thu, 16 Jan 2025 09:54:43 -0500 Subject: [PATCH] [Issue 3498] exclude attachments from search response (#3531) ## Summary Fixes #{[3498](https://github.com/HHS/simpler-grants-gov/issues/3498)} ### Time to review: __5 mins__ ## Changes proposed Modified the search method of our opensearch client to pass through an optional excludes param Modified our search API to set the attachments field to be excluded --------- Co-authored-by: nava-platform-bot --- api/src/adapters/search/opensearch_client.py | 5 ++++- api/src/services/opportunities_v1/search_opportunities.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/src/adapters/search/opensearch_client.py b/api/src/adapters/search/opensearch_client.py index f6a5f381c..b3636ccc3 100644 --- a/api/src/adapters/search/opensearch_client.py +++ b/api/src/adapters/search/opensearch_client.py @@ -216,11 +216,14 @@ def search( search_query: dict, include_scores: bool = True, params: dict | None = None, + excludes: list[str] | None = None, ) -> SearchResponse: if params is None: params = {} - response = self._client.search(index=index_name, body=search_query, params=params) + response = self._client.search( + index=index_name, body=search_query, params=params, _source_excludes=excludes + ) return SearchResponse.from_opensearch_response(response, include_scores) def scroll( diff --git a/api/src/services/opportunities_v1/search_opportunities.py b/api/src/services/opportunities_v1/search_opportunities.py index 70ae5c2e9..664fac423 100644 --- a/api/src/services/opportunities_v1/search_opportunities.py +++ b/api/src/services/opportunities_v1/search_opportunities.py @@ -180,7 +180,7 @@ def search_opportunities( "Querying search index alias %s", index_alias, extra={"search_index_alias": index_alias} ) - response = search_client.search(index_alias, search_request) + response = search_client.search(index_alias, search_request, excludes=["attachments"]) pagination_info = PaginationInfo( page_offset=search_params.pagination.page_offset,