def tearDown(self):
        from invenio_ext.es import es
        self._transaction.rollback()
        es.delete(index='hep', doc_type='record', id=self.new_recid)

        # we need to make sure the new record has been deleted from elasticsearch
        timeout = 15  # [seconds]
        timeout_start = time.time()
        while time.time() < timeout_start + timeout:
            if len(Query('control_number:' + self.new_recid).search()) == 0:
                break
            else:
                time.sleep(1)
        update_citation_count_for_records.delay(self.expected_citation_counts_after_insert.keys())
Esempio n. 2
0
def delete_from_index(mapper, connection, target):
    """Delete record from index."""
    from invenio_ext.es import es

    indices = set(current_app.config['SEARCH_ELASTIC_COLLECTION_INDEX_MAPPING'].values())
    indices.add(current_app.config['SEARCH_ELASTIC_DEFAULT_INDEX'])

    doc_type = current_app.config.get(
        "WORKFLOWS_HOLDING_PEN_DOC_TYPE"
    )
    for index in indices:
        index = current_app.config['WORKFLOWS_HOLDING_PEN_ES_PREFIX'] + index
        es.delete(
            index=index,
            doc_type=doc_type,
            id=target.id,
            ignore=404
        )