def find_one(self, req, **lookup):
     """Find item by id in all collections."""
     hits = self.elastic.es.mget({'ids': [lookup[app.config['ID_FIELD']]]},
                                 es_utils.get_index())
     hits['hits'] = {'hits': hits.pop('docs', [])}
     docs = self._get_docs(hits)
     return docs.first()
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
def publish_report(user_id, search_data):
    """Create report for a search and send it by email"""
    query = es_utils.filter2query(json.loads(search_data['filter']), user_id=user_id)
    found = superdesk.app.data.elastic.es.search(
        body=query, index=es_utils.get_index())
    docs = es_utils.get_docs(found)
    send_report_email(user_id, search_data, docs)
Ejemplo n.º 4
0
def publish_report(user_id, search_data):
    """Create report for a search and send it by email"""
    query = es_utils.filter2query(json.loads(search_data['filter']),
                                  user_id=user_id)
    found = superdesk.app.data.elastic.es.search(body=query,
                                                 index=es_utils.get_index())
    docs = es_utils.get_docs(found)
    send_report_email(user_id, search_data, docs)
Ejemplo n.º 5
0
def publish_report(user_id, search_data):
    """Create report for a search and send it by email"""
    search_filter = json.loads(search_data['filter'])
    query = es_utils.filter2query(search_filter, user_id=user_id)
    repos = es_utils.filter2repos(search_filter)
    types = es_utils.get_doc_types(repos)
    found = superdesk.app.data.elastic.es.search(
        body=query, index=es_utils.get_index(types), doc_type=types)
    docs = es_utils.get_docs(found)
    send_report_email(user_id, search_data, 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
Ejemplo n.º 7
0
 def get_elastic_index(self, types):
     return es_utils.get_index(types)
Ejemplo n.º 8
0
    def get_available_indexes(self):
        """Returns a set of the configured indexes

        :return:
        """
        return set(es_utils.get_index().split(","))
Ejemplo n.º 9
0
    def get_available_indexes(self):
        """Returns a set of the configured indexes

        :return:
        """
        return set(es_utils.get_index().split(','))
Ejemplo n.º 10
0
 def find_one(self, req, **lookup):
     """Find item by id in all collections."""
     hits = self.elastic.es.mget({'ids': [lookup[app.config['ID_FIELD']]]}, es_utils.get_index())
     hits['hits'] = {'hits': hits.pop('docs', [])}
     docs = self._get_docs(hits)
     return docs.first()