def delete(self, start_date=None, end_date=None):
aggs_query = Search(<EOL>using=self.client,<EOL>index=self.aggregation_alias,<EOL>doc_type=self.aggregation_doc_type<EOL>).extra(_source=False)<EOL>range_args = {}<EOL>if start_date:<EOL><INDENT>range_args['<STR_LIT>'] = self._format_range_dt(<EOL>start_date.replace(microsecond=<NUM_LIT:0>))<EOL><DEDENT>if end_date:<EOL><INDENT>range_args['<STR_LIT>'] = self._format_range_dt(<EOL>end_date.replace(microsecond=<NUM_LIT:0>))<EOL><DEDENT>if range_args:<EOL><INDENT>aggs_query = aggs_query.filter('<STR_LIT>', timestamp=range_args)<EOL><DEDENT>bookmarks_query = Search(<EOL>using=self.client,<EOL>index=self.aggregation_alias,<EOL>doc_type=self.bookmark_doc_type<EOL>).sort({'<STR_LIT:date>': {'<STR_LIT>': '<STR_LIT>'}})<EOL>if range_args:<EOL><INDENT>bookmarks_query = bookmarks_query.filter('<STR_LIT>', date=range_args)<EOL><DEDENT>def _delete_actions():<EOL><INDENT>for query in (aggs_query, bookmarks_query):<EOL><INDENT>affected_indices = set()<EOL>for doc in query.scan():<EOL><INDENT>affected_indices.add(doc.meta.index)<EOL>yield dict(_index=doc.meta.index,<EOL>_op_type='<STR_LIT>',<EOL>_id=doc.meta.id,<EOL>_type=doc.meta.doc_type)<EOL><DEDENT>current_search_client.indices.flush(<EOL>index='<STR_LIT:U+002C>'.join(affected_indices), wait_if_ongoing=True)<EOL><DEDENT><DEDENT>bulk(self.client, _delete_actions(), refresh=True)<EOL>
Delete aggregation documents.