From 83a38ff50ed0327a860140ac71d7ad043f0cf7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 5 Jan 2018 17:03:09 +0100 Subject: [PATCH] Admin user search: include aggregations --- pillar/api/search/queries.py | 5 ++--- pillar/api/search/routes.py | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pillar/api/search/queries.py b/pillar/api/search/queries.py index 1f67c310..f19a4d25 100644 --- a/pillar/api/search/queries.py +++ b/pillar/api/search/queries.py @@ -121,7 +121,7 @@ def do_user_search(query: str, terms: dict) -> dict: return response.to_dict() -def do_user_search_admin(query: str) -> dict: +def do_user_search_admin(query: str, terms: dict) -> dict: """ return users seach result dict object search all user fields and provide aggregation information @@ -145,8 +145,7 @@ def do_user_search_admin(query: str) -> dict: else: should = [] - search = Search(using=client, index=current_app.config['ELASTIC_INDICES']['USER']) - search.query = Q('bool', should=should) + search = nested_bool([], should, terms, index_alias='USER') add_aggs_to_search(search, USER_AGG_TERMS) if log.isEnabledFor(logging.DEBUG): diff --git a/pillar/api/search/routes.py b/pillar/api/search/routes.py index 5c91b5df..5cc783c9 100644 --- a/pillar/api/search/routes.py +++ b/pillar/api/search/routes.py @@ -11,7 +11,7 @@ log = logging.getLogger(__name__) blueprint_search = Blueprint('elksearch', __name__) -terms = [ +TERMS = [ 'node_type', 'media', 'tags', 'is_free', 'projectname', 'roles', @@ -32,7 +32,7 @@ def _term_filters() -> dict: return mapping with term field name and provided user term value """ - return {term: request.args.get(term, '') for term in terms} + return {term: request.args.get(term, '') for term in TERMS} @blueprint_search.route('/') @@ -83,7 +83,7 @@ def search_user_admin(): """ searchword = _valid_search() - - data = queries.do_user_search_admin(searchword) + terms = _term_filters() + data = queries.do_user_search_admin(searchword, terms) return jsonify(data)