def delete_writing_task(): query_body = { 'query': { 'filtered': { 'filter': { 'term': { 'compute_status': 4 } } } }, 'size': 100 } result = False try: temp_result = es_xnr.search(index=writing_task_index_name, doc_type=writing_task_index_type, body=query_body)['hits']['hits'] if temp_result: for item in temp_result: task_id = item['_id'] try: es_xnr.delete(index=writing_task_index_name, doc_type=writing_task_index_type, id=task_id) result = True except: result = False except: result = False return result
def lookup_id_delete(xnr_user_no, start_time, end_time, mark=False): query_body = { 'query': { 'filtered': { 'filter': { 'bool': { 'must': [{ 'term': { 'xnr_user_no': xnr_user_no } }, { 'range': { 'trace_time': { 'gte': start_time, 'lte': end_time } } }] } } } } } id_list = [] try: temp_results = es_xnr.search( index=weibo_trace_community_index_name_pre + xnr_user_no, doc_type=weibo_trace_community_index_type, body=query_body)['hits']['hits'] for item in temp_results: print item['_id'] if mark == True: es_xnr.delete(index=weibo_trace_community_index_name_pre + xnr_user_no, doc_type=weibo_trace_community_index_type, id=item['_id']) print 'delete!!!!______' + item['_id'] except: print 'failed!!'
def delete_wx_xnr(wxbot_id): #是否要删除该wxbot捕获的群消息? try: #wx_xnr_logout xnr_logout(wxbot_id) #delete es data try: es_xnr.delete(index=wx_xnr_index_name, doc_type=wx_xnr_index_type, id=wxbot_id) except Exception,e: print e #delete redis data r.delete(wxbot_id) #delete .pkl file cache_path = os.path.join(wx_xnr_data_path, wxbot_id + '.pkl') puid_path = os.path.join(wx_xnr_data_path, wxbot_id + '_puid.pkl') if os.path.isfile(cache_path): os.remove(cache_path) #print 'remove :', cache_path if os.path.isfile(puid_path): os.remove(puid_path) #print 'remove :', puid_path return 1