Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add logging after ES to go with the full arg log #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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)
Loading