def delete_by_query(cls, query, conn=None, es_version="0.90.13", type=None): if conn is None: conn = cls.__conn__ type = cls.get_write_type(type) raw.delete_by_query(conn, type, query, es_version=es_version)
def _action_remove(self, conn, remove_action): obj = remove_action.get("remove") if "index" not in obj: raise StoreException("no index provided for remove action") if "id" not in obj and "query" not in obj: raise StoreException("no id or query provided for remove action") if "id" in obj: raw.delete(conn, obj.get("index"), obj.get("id")) elif "query" in obj: raw.delete_by_query(conn, obj.get("index"), obj.get("query"))
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)