Exemple #1
0
def update_entity_references(entity_id, max_query=1000):
    """Same as above but runs in bulk for a particular entity."""
    q = db.session.query(Reference.document_id)
    q = q.filter(Reference.entity_id == entity_id)
    q = q.filter(Entity.id == entity_id)
    q = q.filter(Entity.state == Entity.STATE_ACTIVE)
    q = q.filter(collection_entity_table.c.entity_id == Entity.id)
    q = q.add_column(collection_entity_table.c.collection_id)
    references = defaultdict(list)
    for row in q:
        references[str(row.document_id)].append(row.collection_id)

    ids = references.keys()
    for i in range(0, len(ids), max_query):
        q = {'query': {'ids': {'values': ids[i:i + max_query]}}}
        bulk_op(document_updates(q, entity_id, references))
    flush_es()
Exemple #2
0
def delete_collection(collection_id):
    """Delete all documents from a particular collection."""
    q = {'query': {'term': {'collection_id': collection_id}}, '_source': False}

    def deletes():
        for res in scan(get_es(), query=q, index=get_es_index(),
                        doc_type=[TYPE_RECORD, TYPE_DOCUMENT, TYPE_ENTITY]):
            yield {
                '_op_type': 'delete',
                '_index': get_es_index(),
                '_parent': res.get('_parent'),
                '_type': res.get('_type'),
                '_id': res.get('_id')
            }

    flush_es()
    bulk_op(deletes())
Exemple #3
0
def delete_collection(collection_id):
    """Delete all documents from a particular collection."""
    q = {'query': {'term': {'collection_id': collection_id}}, '_source': False}

    def deletes():
        for res in scan(get_es(),
                        query=q,
                        index=get_es_index(),
                        doc_type=[TYPE_RECORD, TYPE_DOCUMENT, TYPE_ENTITY]):
            yield {
                '_op_type': 'delete',
                '_index': get_es_index(),
                '_parent': res.get('_parent'),
                '_type': res.get('_type'),
                '_id': res.get('_id')
            }

    flush_es()
    bulk_op(deletes())
Exemple #4
0
def delete_entity_references(entity_id):
    q = {'query': {'term': {'entities.id': entity_id}}}
    bulk_op(document_updates(q, entity_id))
    flush_es()