Skip to content

Commit

Permalink
feat: add logging after ES to go with the full arg log
Browse files Browse the repository at this point in the history
because hits can be quite fat we don't want to log everything,
but we can log summary fields and validate that the hit translation
doesn't lose them
  • Loading branch information
ashultz0 committed Nov 16, 2023
1 parent 4b01497 commit 6bfaf9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion edxsearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" Container module for testing / demoing search """

__version__ = '3.7.1'
__version__ = '3.7.2'
16 changes: 11 additions & 5 deletions search/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
RESERVED_CHARACTERS = "+=><!(){}[]^~*:\\/&|?"


def _translate_hits(es_response):
def _translate_hits(es_response, log_hit_data=False):
"""
Provide result set in our desired format from elasticsearch results.
Expand Down Expand Up @@ -123,11 +123,14 @@ def translate_agg_bucket(bucket, agg_result):
"other": agg_item["sum_other_doc_count"],
}

results = list(map(translate_result, es_response["hits"]["hits"]))
hits_result = es_response["hits"]["hits"]
total = es_response["hits"]["total"]["value"]
max_score = es_response["hits"]["max_score"]
results = list(map(translate_result, hits_result))
response = {
"took": es_response["took"],
"total": es_response["hits"]["total"]["value"],
"max_score": es_response["hits"]["max_score"],
"total": total,
"max_score": max_score,
"results": results,
}
if "aggregations" in es_response:
Expand All @@ -137,6 +140,9 @@ def translate_agg_bucket(bucket, agg_result):
if "total_" not in bucket
}

if log_hit_data:
log.info(f"elastic search results: total {total}, max_score {max_score}, raw hit count {len(hits_result)}")

return response


Expand Down Expand Up @@ -663,4 +669,4 @@ def search(self,
log.exception("error while searching index - %r", ex)
raise

return _translate_hits(es_response)
return _translate_hits(es_response, log_hit_data=log_search_params)

0 comments on commit 6bfaf9e

Please sign in to comment.