def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) types = self._get_types(req) filters = self._get_filters(types) user = g.get('user', {}) if 'invisible_stages' in user: stages = user.get('invisible_stages') else: stages = get_resource_service('users').get_invisible_stages_ids(user.get('_id')) if stages: filters.append({'and': [{'not': {'terms': {'task.stage': stages}}}]}) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: filters.append(dict(limit={'value': app.settings['MAX_SEARCH_DEPTH']})) set_filters(query, filters) hits = self.elastic.es.search(body=query, index=self._get_index(), doc_type=types) docs = self._get_docs(hits) for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) filters = self._get_filters(types) query["aggs"] = aggregations stages = superdesk.get_resource_service("users").get_invisible_stages_ids(g.get("user", {}).get("_id")) if stages: filters.append({"and": [{"not": {"terms": {"task.stage": stages}}}]}) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings["MAX_SEARCH_DEPTH"] == -1: filters.append(dict(limit={"value": app.settings["MAX_SEARCH_DEPTH"]})) set_filters(query, filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, "ingest") # any resource here will do for resource in types: response = {app.config["ITEMS"]: [doc for doc in docs if doc["_type"] == resource]} getattr(app, "on_fetched_resource")(resource, response) getattr(app, "on_fetched_resource_%s" % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) fields = self._get_projected_fields(req) types = self._get_types(req) excluded_stages = self.get_stages_to_exclude() filters = self._get_filters(types, excluded_stages) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: query['terminate_after'] = app.settings['MAX_SEARCH_DEPTH'] if filters: set_filters(query, filters) params = {} if fields: params['_source'] = fields hits = self.elastic.es.search(body=query, index=es_utils.get_index(), doc_type=types, params=params) docs = self._get_docs(hits) for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) filters = self._get_filters(types) query['aggs'] = aggregations stages = superdesk.get_resource_service('users').get_invisible_stages_ids(g.get('user', {}).get('_id')) if stages: filters.append({'and': [{'not': {'terms': {'task.stage': stages}}}]}) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: filters.append(dict(limit={'value': app.settings['MAX_SEARCH_DEPTH']})) set_filters(query, filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, 'ingest') # any resource here will do for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """Run elastic search agains on multiple doc types.""" elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) query['aggs'] = aggregations set_filters(query, self.private_filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, 'ingest') # any resource here will do for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """Run elastic search agains on multiple doc types.""" elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) query['aggs'] = aggregations # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: set_filters(query, self.private_filters + [{'limit': {'value': app.settings['MAX_SEARCH_DEPTH']}}]) else: set_filters(query, self.private_filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, 'ingest') # any resource here will do for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """Run elastic search agains on multiple doc types.""" elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) query['aggs'] = aggregations set_filters(query, self.private_filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, 'ingest') # any resource here will do for resource in types: response = { app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource] } getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) fields = self._get_projected_fields(req) types = self._get_types(req) user = g.get('user', {}) if 'invisible_stages' in user: stages = user.get('invisible_stages') else: stages = get_resource_service('users').get_invisible_stages_ids( user.get('_id')) filters = self._get_filters(types, stages) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: query['terminate_after'] = app.settings['MAX_SEARCH_DEPTH'] set_filters(query, filters) params = {} if fields: params['_source'] = fields hits = self.elastic.es.search(body=query, index=self._get_index(), doc_type=types, params=params) docs = self._get_docs(hits) for resource in types: response = { app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource] } getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def run_query(self, params, args): query = params.get('source') or {} if 'query' not in query: query['query'] = {'filtered': {}} aggs = self.get_request_aggregations(params, args) if aggs: query['aggs'] = aggs types = params.get('repo') if not types: types = self.repos.copy() else: types = types.split(',') # If the repos array is still empty after filtering, then return the default repos types = [repo for repo in types if repo in self.repos] or self.repos.copy() excluded_stages = self.get_stages_to_exclude() filters = self._get_filters(types, excluded_stages) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: query['terminate_after'] = app.settings['MAX_SEARCH_DEPTH'] if filters: set_filters(query, filters) index = self.get_elastic_index(types) hits = self.elastic.es.search( body=query, index=index, doc_type=types, params={} ) docs = self._get_docs(hits) for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) types = self._get_types(req) filters = self._get_filters(types) stages = superdesk.get_resource_service( 'users').get_invisible_stages_ids(g.get('user', {}).get('_id')) if stages: filters.append( {'and': [{ 'not': { 'terms': { 'task.stage': stages } } }]}) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: filters.append( dict(limit={'value': app.settings['MAX_SEARCH_DEPTH']})) set_filters(query, filters) hits = self.elastic.es.search(body=query, index=self._get_index(), doc_type=types) docs = self._get_docs(hits) for resource in types: response = { app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource] } getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """Run elastic search agains on multiple doc types.""" elastic = app.data.elastic query = self._get_query(req) types = self._get_types(req) query['aggs'] = aggregations stages = superdesk.get_resource_service( 'users').get_invisible_stages_ids(g.get('user', {}).get('_id')) if stages: self.private_filters.append( {'and': [{ 'not': { 'terms': { 'task.stage': stages } } }]}) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: set_filters( query, self.private_filters + [{ 'limit': { 'value': app.settings['MAX_SEARCH_DEPTH'] } }]) else: set_filters(query, self.private_filters) hits = elastic.es.search(body=query, index=elastic.index, doc_type=types) docs = elastic._parse_hits(hits, 'ingest') # any resource here will do for resource in types: response = { app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource] } getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) fields = self._get_projected_fields(req) types = self._get_types(req) excluded_stages = self.get_stages_to_exclude() filters = self._get_filters(types, excluded_stages) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: query['terminate_after'] = app.settings['MAX_SEARCH_DEPTH'] if filters: set_filters(query, filters) params = {} if fields: params['_source'] = fields hits = self.elastic.es.search(body=query, index=es_utils.get_index(types), doc_type=types, params=params) docs = self._get_docs(hits) for resource in types: response = { app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource] } getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs
def get(self, req, lookup): """ Runs elastic search on multiple doc types. """ query = self._get_query(req) fields = self._get_projected_fields(req) types = self._get_types(req) user = g.get('user', {}) if 'invisible_stages' in user: stages = user.get('invisible_stages') else: stages = get_resource_service('users').get_invisible_stages_ids(user.get('_id')) filters = self._get_filters(types, stages) # if the system has a setting value for the maximum search depth then apply the filter if not app.settings['MAX_SEARCH_DEPTH'] == -1: query['terminate_after'] = app.settings['MAX_SEARCH_DEPTH'] set_filters(query, filters) params = {} if fields: params['_source'] = fields hits = self.elastic.es.search(body=query, index=self._get_index(), doc_type=types, params=params) docs = self._get_docs(hits) for resource in types: response = {app.config['ITEMS']: [doc for doc in docs if doc['_type'] == resource]} getattr(app, 'on_fetched_resource')(resource, response) getattr(app, 'on_fetched_resource_%s' % resource)(response) return docs