Admin user search: include aggregations
This commit is contained in:
parent
67851752fa
commit
83a38ff50e
@ -121,7 +121,7 @@ def do_user_search(query: str, terms: dict) -> dict:
|
|||||||
return response.to_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
|
return users seach result dict object
|
||||||
search all user fields and provide aggregation information
|
search all user fields and provide aggregation information
|
||||||
@ -145,8 +145,7 @@ def do_user_search_admin(query: str) -> dict:
|
|||||||
else:
|
else:
|
||||||
should = []
|
should = []
|
||||||
|
|
||||||
search = Search(using=client, index=current_app.config['ELASTIC_INDICES']['USER'])
|
search = nested_bool([], should, terms, index_alias='USER')
|
||||||
search.query = Q('bool', should=should)
|
|
||||||
add_aggs_to_search(search, USER_AGG_TERMS)
|
add_aggs_to_search(search, USER_AGG_TERMS)
|
||||||
|
|
||||||
if log.isEnabledFor(logging.DEBUG):
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
|
|||||||
blueprint_search = Blueprint('elksearch', __name__)
|
blueprint_search = Blueprint('elksearch', __name__)
|
||||||
|
|
||||||
|
|
||||||
terms = [
|
TERMS = [
|
||||||
'node_type', 'media',
|
'node_type', 'media',
|
||||||
'tags', 'is_free', 'projectname',
|
'tags', 'is_free', 'projectname',
|
||||||
'roles',
|
'roles',
|
||||||
@ -32,7 +32,7 @@ def _term_filters() -> dict:
|
|||||||
return mapping with term field name
|
return mapping with term field name
|
||||||
and provided user term value
|
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('/')
|
@blueprint_search.route('/')
|
||||||
@ -83,7 +83,7 @@ def search_user_admin():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
searchword = _valid_search()
|
searchword = _valid_search()
|
||||||
|
terms = _term_filters()
|
||||||
data = queries.do_user_search_admin(searchword)
|
data = queries.do_user_search_admin(searchword, terms)
|
||||||
|
|
||||||
return jsonify(data)
|
return jsonify(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user