def delete_matching_documents(index, type, field, value, **kwargs):
    # open connection if one hasn't been provided
    conn = kwargs.get('conn', False)
    if not conn:
        conn = connect_and_create_index(index)

    # a max_documents of 0 means unlimited
    max_documents = kwargs.get('max_documents', 0)

    # cycle through fields to find matches
    documents = conn.search_raw(
        indices=[index],
        doc_types=[type],
        query=pyes.FieldQuery(pyes.FieldParameter(field, value))
    )

    count = 0
    if len(documents['hits']['hits']) > 0:
        for hit in documents['hits']['hits']:
            document_id = hit['_id']
            conn.delete(index, type, document_id)
            count = count + 1
            if count == max_documents:
                return count

    return count
def connect_and_get_aip_data(uuid):
    conn = connect_and_create_index('aips')
    aips = conn.search(
        query=pyes.FieldQuery(pyes.FieldParameter('uuid', uuid)),
        fields='uuid,name,filePath,size,origin,created'
    )
    return aips[0]
Esempio n. 3
0
def archival_storage_search_augment_aip_results(conn, aips):
    for aip_uuid in aips:
        documents = conn.search_raw(
            query=pyes.FieldQuery(pyes.FieldParameter('uuid', aip_uuid.term)))
        if len(documents['hits']['hits']) > 0:
            aip_uuid.name = documents['hits']['hits'][0]['_source']['name']
            aip_uuid.size = '{0:.2f} MB'.format(
                documents['hits']['hits'][0]['_source']['size'])
            aip_uuid.date = documents['hits']['hits'][0]['_source']['created']
        else:
            aip_uuid.name = '(data missing)'
def connect_and_delete_aip_files(uuid):
    deleted = 0
    conn = pyes.ES(getElasticsearchServerHostAndPort())
    documents = conn.search_raw(query=pyes.FieldQuery(pyes.FieldParameter('AIPUUID', uuid)))
    if len(documents['hits']['hits']) > 0:
        for hit in documents['hits']['hits']:
            document_id = hit['_id']
            conn.delete('aips', 'aipfile', document_id)
            deleted = deleted + 1
        print str(deleted) + ' index documents removed.'
    else:
        print 'No AIP files found.'
Esempio n. 5
0
def search_augment_aip_results(conn, aips):
    for aip_uuid in aips:
        documents = conn.search_raw(query=pyes.FieldQuery(
            pyes.FieldParameter('uuid', aip_uuid.term)),
                                    fields='name,size,created')
        if len(documents['hits']['hits']) > 0:
            aip_uuid.name = documents['hits']['hits'][0]['fields']['name']
            aip_uuid.size = '{0:.2f} MB'.format(
                documents['hits']['hits'][0]['fields']['size'])
            aip_uuid.date = documents['hits']['hits'][0]['fields']['created']
            aip_uuid.document_id_no_hyphens = documents['hits']['hits'][0][
                '_id'].replace('-', '____')
        else:
            aip_uuid.name = '(data missing)'
def connect_and_remove_sip_transfer_files(uuid):
    # get file UUIDs for each file in the SIP
    sql = "SELECT fileUUID from Files WHERE sipUUID='" + MySQLdb.escape_string(uuid) + "'"

    rows = databaseInterface.queryAllSQL(sql)

    if len(rows) > 0:
        conn = connect_and_create_index('transfers')

        # cycle through file UUIDs and delete files from transfer backlog
        for row in rows:
            documents = conn.search_raw(query=pyes.FieldQuery(pyes.FieldParameter('fileuuid', row[0])))
            if len(documents['hits']['hits']) > 0:
                document_id = documents['hits']['hits'][0]['_id']
                conn.delete('transfers', 'transferfile', document_id)
def connect_and_change_transfer_file_status(uuid, status):
    # get file UUIDs for each file in the SIP
    sql = "SELECT fileUUID from Files WHERE transferUUID='" + MySQLdb.escape_string(uuid) + "'"

    rows = databaseInterface.queryAllSQL(sql)

    if len(rows) > 0:
        conn = connect_and_create_index('transfers')

        # cycle through file UUIDs and update status
        for row in rows:
            documents = conn.search_raw(query=pyes.FieldQuery(pyes.FieldParameter('fileuuid', row[0])))
            if len(documents['hits']['hits']) > 0:
                document_id = documents['hits']['hits'][0]['_id']
                conn.update({'status': status}, 'transfers', 'transferfile', document_id)
    return len(rows)
def connect_and_get_aip_data(uuid):
    conn = connect_and_create_index('aips')
    aips = conn.search(
        query=pyes.FieldQuery(pyes.FieldParameter('uuid', uuid)))
    return aips[0]