Skip to content
Snippets Groups Projects
Commit f894c387 authored by Harsha Kethineni's avatar Harsha Kethineni
Browse files

new endpoint for string field type ahead

parent 476c1121
No related branches found
No related tags found
No related merge requests found
......@@ -100,10 +100,11 @@ endpoints = [
# Search
route('/dataexplorer/search', DataExplorerHandler, h='search', m=['POST']),
route('/dataexplorer/facets', DataExplorerHandler, h='get_facets', m=['POST']),
route('/dataexplorer/search/fields', DataExplorerHandler, h='search_fields', m=['POST']),
route('/dataexplorer/index/fields', DataExplorerHandler, h='index_field_names', m=['POST']),
route('/dataexplorer/search', DataExplorerHandler, h='search', m=['POST']),
route('/dataexplorer/facets', DataExplorerHandler, h='get_facets', m=['POST']),
route('/dataexplorer/search/fields', DataExplorerHandler, h='search_fields', m=['POST']),
route('/dataexplorer/search/fields/aggregate', DataExplorerHandler, h='get_type_ahead_values', m=['POST']),
route('/dataexplorer/index/fields', DataExplorerHandler, h='index_field_names', m=['POST']),
# Users
......
......@@ -251,6 +251,34 @@ class DataExplorerHandler(base.RequestHandler):
return return_type, modified_filters, search_string
@require_login
def get_type_ahead_values(self):
"""
Return list of type ahead values for a key given a value
that the user has already started to type in for the value of
a custom string field
"""
user_value = self.request.json_body['value']
custom_field = self.request.json_body['field_name']
body = {
"size": 0,
"query": {"match" : { custom_field : user_value}},
"aggs" : {
"results" : {
"terms" : {
"field" : custom_field + ".raw",
"size" : 15
}
}
}
}
aggs = config.es.search(
index='data_explorer',
doc_type='flywheel',
body=body
)['aggregations']['results']['buckets']
aggs = [bucket['key'] for bucket in aggs]
return {'type_aheads': aggs}
@require_login
def get_facets(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment