def delete_document(document_id, sync=False): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} schemata = (DocumentRecord.SCHEMA_PAGE, DocumentRecord.SCHEMA_ROW, Document.SCHEMA) query_delete(entities_read_index(schemata), q, sync=sync)
def delete_collection(collection_id, wait=True): """Delete all documents from a particular collection.""" query_delete({'term': {'collection_id': collection_id}}, wait=wait) es.delete(index=es_index, doc_type=TYPE_COLLECTION, id=collection_id, ignore=[404])
def delete_entities(collection_id, origin=None, schema=None, sync=False): """Delete entities from a collection.""" filters = [{"term": {"collection_id": collection_id}}] if origin is not None: filters.append({"term": {"origin": origin}}) query = {"bool": {"filter": filters}} query_delete(entities_read_index(schema), query, sync=sync)
def delete_xref(collection, entity_id=None, sync=False): """Delete xref matches of an entity or a collection.""" shoulds = [ { 'term': { 'collection_id': collection.id } }, { 'term': { 'match_collection_id': collection.id } }, ] if entity_id is not None: shoulds = [ { 'term': { 'entity_id': entity_id } }, { 'term': { 'match_id': entity_id } }, ] query = {'bool': {'should': shoulds, 'minimum_should_match': 1}} query_delete(xref_index(), query, sync=sync)
def delete_xref(collection, entity_id=None, sync=False): """Delete xref matches of an entity or a collection.""" shoulds = [ { "term": { "collection_id": collection.id } }, { "term": { "match_collection_id": collection.id } }, ] if entity_id is not None: shoulds = [ { "term": { "entity_id": entity_id } }, { "term": { "match_id": entity_id } }, ] query = {"bool": {"should": shoulds, "minimum_should_match": 1}} query_delete(xref_index(), query, sync=sync)
def delete_entities(collection_id, mapping_id=None, schema=None, sync=False): """Delete entities from a collection.""" filters = [{'term': {'collection_id': collection_id}}] if mapping_id is not None: filters.append({'term': {'mapping_id': mapping_id}}) query = {'bool': {'filter': filters}} query_delete(entities_read_index(schema), query, sync=sync)
def delete_notifications(channel, sync=False): """Delete entities from a collection.""" query = { 'bool': { 'filter': [{'term': {'channels': channel}}] } } query_delete(notifications_index(), query, sync=sync)
def delete_entities(collection_id, schema=None, bulk_only=False): """Delete entities from a collection.""" filters = [{'term': {'collection_id': collection_id}}] if bulk_only: filters.append({'term': {'bulk': True}}) if schema is not None: filters.append({'term': {'schemata': schema.name}}) query = {'bool': {'filter': filters}} query_delete(entities_read_index(schema), query)
def delete_collection(collection_id, wait=True): """Delete all documents from a particular collection.""" query = {'term': {'collection_id': collection_id}} query_delete(records_index(), query, wait=wait) query_delete(entities_index(), query, wait=wait) es.delete(index=collections_index(), doc_type=collection_type(), id=collection_id, ignore=[404])
def delete_entity(entity_id, exclude=None, sync=False): """Delete an entity from the index.""" if exclude is not None: exclude = entities_write_index(exclude) for entity in entities_by_ids(entity_id, excludes='*'): index = entity.get('_index') if index == exclude: continue es.delete(index=index, id=entity_id, refresh=refresh_sync(sync)) q = {'term': {'entities': entity_id}} query_delete(entities_read_index(), q, sync=sync)
def delete_entity_leads(entity_id): """Delete all entity-related leads from the index.""" q = { 'bool': { 'should': [ {'term': {'entity_id': entity_id}}, {'term': {'match_id': entity_id}} ] } } query_delete(q, doc_type=TYPE_LEAD)
def delete_entities(collection_id): """Delete entities from a collection.""" query = { 'bool': { 'must_not': { 'term': { 'schemata': 'Document' } }, 'must': { 'term': { 'collection_id': collection_id } } } } query_delete(entities_index(), query)
def delete_documents(collection_id): """Delete documents from a collection.""" query = { 'bool': { 'must': [{ 'term': { 'schemata': 'Document' } }, { 'term': { 'collection_id': collection_id } }] } } query_delete(entities_index(), query) records_query = {'term': {'collection_id': collection_id}} query_delete(records_index(), records_query)
def delete_entity(entity_id, exclude=None, sync=False): """Delete an entity from the index.""" if exclude is not None: exclude = entities_write_index(exclude) for entity in entities_by_ids(entity_id, excludes='*'): index = entity.get('_index') if index == exclude: continue try: es.delete(index=index, id=entity_id, refresh=refresh_sync(sync)) q = {'term': {'entities': entity_id}} query_delete(entities_read_index(), q, sync=sync) except NotFoundError: # This is expected in some cases. For example, when 2 Things are # connected by an Interval and all the 3 entities get deleted # simultaneously, Aleph tries to delete the Interval thrice due to # recursive deletion of adjacent entities. ElasticSearch throws a # 404 in that case. # In those cases, we want to skip both the `es.delete` step and # the `query_delete` step. log.warning("Delete failed for entity %s - not found", entity_id) continue
def clear_records(document_id, refresh=True): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} query_delete(records_index(), q) if refresh: refresh_index(index=records_index())
def delete_doc_type(doc_type): query_delete({'match_all': {}}, doc_type=doc_type, wait=False)
def delete_records(document_id=None, collection_id=None, sync=False): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} if collection_id is not None: q = {'term': {'collection_id': collection_id}} query_delete(records_read_index(), q, refresh=sync)
def clear_records(document_id): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} query_delete(q, doc_type=TYPE_RECORD)
def delete_notifications(channel, sync=False): """Delete entities from a collection.""" query = {"bool": {"filter": [{"term": {"channels": channel}}]}} query_delete(notifications_index(), query, sync=sync)
def delete_collection(collection_id): """Delete all documents from a particular collection.""" query_delete({'term': {'collection_id': collection_id}}) query_delete({'term': {'entity_collection_id': collection_id}})
def delete_collection(collection_id): """Delete all documents from a particular collection.""" q = {'ids': {'values': str(collection_id)}} query_delete(collections_index(), q) refresh_index(index=collections_index())
def delete_collection_entities(): q = {'exists': {'field': 'collection_id'}} query_delete(q, doc_type=TYPE_ENTITY)
def delete_entity(entity_id): """Delete an entity from the index.""" q = {'ids': {'values': str(entity_id)}} query_delete(entities_index(), q) refresh_index(index=entities_index())
def delete_entities(collection_id, schema=None, sync=False): """Delete entities from a collection.""" filters = [{'term': {'collection_id': collection_id}}] query = {'bool': {'filter': filters}} query_delete(entities_read_index(schema), query, sync=sync)
def delete_records(document_id, sync=False): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} query_delete(records_read_index(), q, refresh=sync)
def delete_records(collection_id): records_query = {'term': {'collection_id': collection_id}} query_delete(records_read_index(), records_query)
def clear_records(document_id): """Delete all records associated with the given document.""" q = {'term': {'document_id': document_id}} query_delete(records_index(), q)