Exemple #1
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])
Exemple #2
0
def delete_documents(collection_id):
    """Delete documents from a collection."""
    records_query = {'term': {'collection_id': collection_id}}
    query_delete(records_index(), records_query)
    refresh_index(index=records_index())
    query = {
        'bool': {
            'must': [{
                'term': {
                    'schemata': 'Document'
                }
            }, {
                'term': {
                    'collection_id': collection_id
                }
            }]
        }
    }
    query_delete(entities_index(), query)
Exemple #3
0
def iter_records(document_id=None, collection_id=None):
    """Scan all records matching the given criteria."""
    filters = []
    if document_id is not None:
        filters.append({'term': {'document_id': document_id}})
    if collection_id is not None:
        filters.append({'term': {'collection_id': collection_id}})
    query = {'query': {'bool': {'filter': filters}}, 'sort': ['_doc']}
    for res in scan(es, index=records_index(), query=query, scroll='1410m'):
        yield unpack_result(res)
Exemple #4
0
def index_records(document):
    if not document.supports_records:
        return

    clear_records(document.id, refresh=False)
    while True:
        try:
            bulk_op(generate_records(document))
            refresh_index(index=records_index())
            return
        except BulkIndexError as exc:
            log.exception(exc)
            time.sleep(RETRY_DELAY)
Exemple #5
0
def index_records(document):
    if not document.supports_records:
        return

    clear_records(document.id)
    for attempt in count():
        try:
            bulk_op(generate_records(document))
            refresh_index(records_index())
            return
        except Exception as exc:
            log.warning('Failed to index records: %s', exc)
        backoff_cluster(failures=attempt)
Exemple #6
0
def delete_documents(collection_id, wait=True):
    """Delete documents from a collection."""
    query = {
        'bool': {
            'must': [{
                'term': {
                    'schemata': 'Document'
                }
            }, {
                'term': {
                    'collection_id': collection_id
                }
            }]
        }
    }
    query_delete(entities_index(), query, wait=wait)
    records_query = {'term': {'collection_id': collection_id}}
    query_delete(records_index(), records_query, wait=wait)
Exemple #7
0
 def get_index(self):
     return records_index()
Exemple #8
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)
Exemple #9
0
def delete_document(document_id):
    clear_records(document_id)
    delete_entity(document_id)
    refresh_index(index=records_index())
Exemple #10
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())
Exemple #11
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_index(), q, wait_for_completion=sync, refresh=sync)