From ba8ee783f78662721306c9a5aebb7e6244a22eb0 Mon Sep 17 00:00:00 2001 From: Andy Shultz Date: Wed, 15 Nov 2023 09:43:10 -0500 Subject: [PATCH] feat: add arg and setting to trigger more complete search log we don't want to trigger logging on every single ES search or force logging into other courseware search uses, so arg + setting just for courseware search --- search/api.py | 2 ++ search/elastic.py | 4 ++++ search/search_engine_base.py | 1 + search/tests/mock_search_engine.py | 1 + 4 files changed, 8 insertions(+) diff --git a/search/api.py b/search/api.py index 48cb4d42..177e909a 100644 --- a/search/api.py +++ b/search/api.py @@ -62,6 +62,7 @@ def perform_course_search( ) if not searcher: raise NoSearchEngineError("No search engine specified in settings.SEARCH_ENGINE") + log_search_params = getattr(settings, "SEARCH_COURSEWARE_CONTENT_LOG_PARAMS", False) results = searcher.search( query_string=search_term, @@ -70,6 +71,7 @@ def perform_course_search( exclude_dictionary=exclude_dictionary, size=size, from_=from_, + log_search_params=log_search_params, ) # post-process the result diff --git a/search/elastic.py b/search/elastic.py index f895564a..4e38093a 100644 --- a/search/elastic.py +++ b/search/elastic.py @@ -477,6 +477,7 @@ def search(self, aggregation_terms=None, exclude_ids=None, use_field_match=False, + log_search_params=False, **kwargs): # pylint: disable=arguments-differ, unused-argument """ Implements call to search the index for the desired content. @@ -653,6 +654,9 @@ def search(self, if aggregation_terms: body["aggs"] = _process_aggregation_terms(aggregation_terms) + if log_search_params: + log.info(f"full elastic search body {body}") + try: es_response = self._es.search(index=self._prefixed_index_name, body=body, **kwargs) except exceptions.ElasticsearchException as ex: diff --git a/search/search_engine_base.py b/search/search_engine_base.py index e2b9ef1f..49b2e367 100644 --- a/search/search_engine_base.py +++ b/search/search_engine_base.py @@ -48,6 +48,7 @@ def search(self, filter_dictionary=None, exclude_dictionary=None, aggregation_terms=None, + log_search_params=False, **kwargs): # pylint: disable=too-many-arguments """ Search for matching documents within the search index. diff --git a/search/tests/mock_search_engine.py b/search/tests/mock_search_engine.py index 10f243e4..52894800 100644 --- a/search/tests/mock_search_engine.py +++ b/search/tests/mock_search_engine.py @@ -340,6 +340,7 @@ def search(self, filter_dictionary=None, exclude_dictionary=None, aggregation_terms=None, + log_search_params=False, **kwargs): # pylint: disable=too-many-arguments """ Perform search upon documents within index.