Skip to content
Merged
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
1 change: 1 addition & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def prefix(path, routes):
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='aggregate_field_values', m=['POST']),
route('/dataexplorer/search/nodes', DataExplorerHandler, h='get_nodes', m=['POST']),
route('/dataexplorer/index/fields', DataExplorerHandler, h='index_field_names', m=['POST']),

# Users
Expand Down
56 changes: 55 additions & 1 deletion api/handlers/dataexplorerhandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
import json

from elasticsearch import ElasticsearchException, TransportError
from elasticsearch import ElasticsearchException, TransportError, helpers

from ..web import base
from .. import config
Expand Down Expand Up @@ -470,6 +470,60 @@ def get_facets(self):
aggs['by_session']['subject.age'] = age_node['subject.age']
return {'facets': aggs}

def search_size(self, return_type):
body = {
"size": 0,
"aggs" : {
"count" : {
"cardinality" : {
"field" : return_type + "._id",
"precision_threshold": 100000
}
}
}
}

size = config.es.search(
index='data_explorer',
doc_type='flywheel',
body=body)['aggregations']['count']['value']
size = int(size*1.02)
return size

def get_nodes(self):

return_type, filters, search_string = self._parse_request()
if return_type == 'file':
return self.get_file_nodes(return_type, filters, search_string)

size = self.search_size(return_type)
body = self._construct_query(return_type, search_string, filters, size)

body['aggs']['by_container'].pop('aggs')
body['_source'] = [return_type + "._id"]

nodes = []
results = config.es.search(
index='data_explorer',
doc_type='flywheel',
body=body)['aggregations']['by_container']['buckets']

for result in results:
nodes.append({'level': return_type, '_id': result['key']})
return {'nodes':nodes}

def get_file_nodes(self, return_type, filters, search_string):

query = self._construct_file_query(return_type, filters, search_string)['query']

nodes = []
results = helpers.scan(client=config.es, query={'query': query}, scroll='5m', size=1000, index='data_explorer', doc_type='flywheel', _source=[return_type+'._id'])
log.debug(results)
for result in results:
nodes.append({'level': return_type, '_id': result['_source'][return_type]['_id']})
return {'nodes':nodes}


@require_login
def search_fields(self):
field_query = self.request.json_body.get('field')
Expand Down