Пример #1
0
# Connection to the ES index
conn = raw.make_connection(None, 'localhost', 9200, 'doaj')

archv_query = {
            "query" : {
                "term" : {
                    "admin.in_doaj" : "false"
                    }
                }
            }

## Journals ##
json_writer = tasks.JSONListWriter('journals_not_in_doaj.json')

# Dump all journals not in DOAJ to file
tasks.dump(conn, 'journal', q=archv_query.copy(), out=json_writer)
json_writer.close()

# Ask how many journals will be deleted, and delete them.
j_deleted = models.Journal.query(q=archv_query.copy())['hits']['total']
models.Journal.delete_by_query(archv_query)

## Articles ##
json_writer2 = tasks.JSONListWriter('articles_not_in_doaj.json')

# Dump all articles not in DOAJ to file
tasks.dump(conn, 'article', q=archv_query.copy(), out=json_writer2)
json_writer2.close()

# Ask how many articles will be deleted, and delete them.
a_deleted = models.Article.query(q=archv_query.copy())['hits']['total']
Пример #2
0
from esprit import tasks, raw

'''Delete all rejected applications in DOAJ'''

# Connection to the ES index
conn = raw.make_connection(None, 'localhost', 9200, 'doaj')

rej_query = {
            "query" : {
                "term" : {
                    "admin.application_status.exact" : "rejected"
                    }
                }
            }

json_writer = tasks.JSONListWriter('rejected_applications.json')

# Dump all rejected suggestions to file
tasks.dump(conn, 'suggestion', q=rej_query.copy(), out=json_writer)
json_writer.close()

# Ask how many rejected applications will be deleted.
n_deleted = raw.search(conn, 'suggestion', rej_query).json()['hits']['total']

# Delete all rejected suggestions.
raw.delete_by_query(conn, 'suggestion', rej_query)

print "\n{0} suggestions archived to file 'rejected_applications.json' and deleted from index.".format(n_deleted)