Admin user search: include aggregations

This commit is contained in:
Sybren A. Stüvel 2018-01-05 17:03:09 +01:00
parent 67851752fa
commit 83a38ff50e
2 changed files with 6 additions and 7 deletions

View File

@ -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):

View File

@ -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)