Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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])
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def delete_notifications(channel, sync=False):
    """Delete entities from a collection."""
    query = {
        'bool': {
            'filter': [{'term': {'channels': channel}}]
        }
    }
    query_delete(notifications_index(), query, sync=sync)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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])
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
Arquivo: leads.py Projeto: wcyn/aleph
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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())
Exemplo n.º 18
0
def delete_doc_type(doc_type):
    query_delete({'match_all': {}}, doc_type=doc_type, wait=False)
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
def delete_notifications(channel, sync=False):
    """Delete entities from a collection."""
    query = {"bool": {"filter": [{"term": {"channels": channel}}]}}
    query_delete(notifications_index(), query, sync=sync)
Exemplo n.º 22
0
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}})
Exemplo n.º 23
0
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())
Exemplo n.º 24
0
def delete_collection_entities():
    q = {'exists': {'field': 'collection_id'}}
    query_delete(q, doc_type=TYPE_ENTITY)
Exemplo n.º 25
0
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())
Exemplo n.º 26
0
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)
Exemplo n.º 27
0
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)
Exemplo n.º 28
0
def delete_records(collection_id):
    records_query = {'term': {'collection_id': collection_id}}
    query_delete(records_read_index(), records_query)
Exemplo n.º 29
0
def clear_records(document_id):
    """Delete all records associated with the given document."""
    q = {'term': {'document_id': document_id}}
    query_delete(records_index(), q)