Exemple #1
0
    def _filter_by_id(self, doc_ids):
        """Get docs matching one or more ids from multiple indexes.

        Takes a document id or a list of document ids, and returns
        documents matching the given id(s) from indexes associated with
        the Engine instance. Used to locate documents across multiple
        indexes, as in the case of a time series (timestamped indexes).
        """
        is_list = isinstance(doc_ids, list)
        if not is_list:
            doc_ids = [doc_ids]

        params = self._params_for_search
        query = es_queries.ids_query(doc_ids)
        params.update({
            'body': query,
            '_source': True,
            'ignore_unavailable': True
        })
        results = ELASTICSEARCH.search(**params)
        formatted_results = es_results.get_source(results)
        if is_list:
            return formatted_results
        elif len(formatted_results) > 0:
            return formatted_results[0]
Exemple #2
0
    def _remove_by_id_wildcard(self, doc_ids):
        """Remove one or more docs from multiple indexes.

        Takes a document id or a list of document ids and removes the
        document(s) from the Elasticsearch index(es) associated with the
        Engine. Used for removing documents from time series indexes.
        """
        params = self._params_for_search
        query = es_queries.ids_query(doc_ids)
        params.update({
            'body': query,
            '_source': False,
            'ignore_unavailable': True
        })
        results = ELASTICSEARCH.search(**params)

        for hit in es_results.get_hits(results):
            params = es_results.get_doc_info(hit)
            params.update({'refresh': True})
            ELASTICSEARCH.delete(**params)