def delete_attribute(attribute_name): status = False try: result = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: return status attribute_value = json.loads(result['value']) es.delete(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name) # delete attribute in user_portrait query = [] for value in attribute_value: query.append({'match':{attribute_name: value}}) try: attribute_user_result = es.search(index=user_index_name, doc_type=user_index_type, \ body={'query':{'bool':{'must':query}}})['hits']['hits'] except: attribute_user_result = [] if attribute_user_result==[]: status = True return status bulk_action = [] for user_dict in attribute_user_result: try: user_item = user_dict['_source'] except: next user_item.pop(attribute) user = user_item['uid'] action = {'index':{'_id':str(user)}} bulk_action.extend([action, user_item]) es.bulk(bulk_action, index=user_index_name, doc_type=index_type) status = True return status
def ajax_delete_task(): # delete task based on task_name task_name = request.args.get('task_name','') # must if task_name: es.delete(index=index_manage_sensing_task, doc_type=task_doc_type, id=task_name) try: delete_es(task_name) except Exception, r: print Exception, r return json.dumps(['1'])
def ajax_delete_task(): # delete task based on task_name task_name = request.args.get('task_name', '') # must if task_name: es.delete(index=index_manage_sensing_task, doc_type=task_doc_type, id=task_name) try: delete_es(task_name) except Exception, r: print Exception, r return json.dumps(['1'])
def ajax_delete_task(): # delete task based on task_name task_name = request.args.get('task_name','') # must user = request.args.get('user', '') if task_name and user: _id = user + "-" + task_name es.delete(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id) try: delete_es(_id) except Exception, r: print Exception, r return json.dumps(['1'])
def ajax_delete_task(): # delete task based on task_name task_name = request.args.get('task_name','') # must user = request.args.get('user', '') print task_name, user if task_name and user: _id = user + "-" + task_name es.delete(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id) try: delete_es(_id) except Exception, r: print Exception, r return json.dumps(['1'])
def delete_group_results(task_name, submit_user): task_id = submit_user + '-' + task_name #step1: get group uid list try: group_result = es_group_result.get(index=group_index_name, doc_type=group_index_type,\ id=task_id)['_source'] except: return False uid_list = group_result['uid_list'] #step2: update group_tag in user_portrait query_body = {'query': {'term': {'group': task_id}}} try: user_portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type,\ body={'ids': uid_list})['docs'] except: user_portrait_result = [] bulk_action = [] for item in user_portrait_result: uid = item['_id'] if item['found'] == True: try: source = item['_source'] except: source = {} try: group_tag = source['group'] except: group_tag = '' if group_tag != '': new_group_tag_list = [] group_tag_list = group_tag.split('&') for group_tag_item in group_tag_list: if group_tag_item != task_id and group_tag_item != '[email protected]': new_group_tag_list.append(group_tag_item) new_group_tag = '&'.join(new_group_tag_list) else: new_group_tag = '' action = {'update': {'_id': uid}} bulk_action.extend([action, {'doc': {'group': new_group_tag}}]) if bulk_action: print 'bulk_action:', bulk_action es_user_portrait.bulk(bulk_action, index=portrait_index_name, doc_type=portrait_index_type) #step3: delete group results in group_manage try: print 'yes delete' result = es.delete(index=index_name, doc_type=index_type, id=task_id) except: return False return True
def delete_group_results(task_name, submit_user): task_id = submit_user + '-' + task_name #step1: get group uid list try: group_result = es_group_result.get(index=group_index_name, doc_type=group_index_type,\ id=task_id)['_source'] except: return False uid_list = group_result['uid_list'] #step2: update group_tag in user_portrait query_body = {'query':{'term':{'group': task_id}}} try: user_portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type,\ body={'ids': uid_list})['docs'] except: user_portrait_result = [] bulk_action = [] for item in user_portrait_result: uid = item['_id'] if item['found'] == True: try: source = item['_source'] except: source = {} try: group_tag = source['group'] except: group_tag = '' if group_tag != '': new_group_tag_list = [] group_tag_list = group_tag.split('&') for group_tag_item in group_tag_list: if group_tag_item != task_id and group_tag_item != '[email protected]': new_group_tag_list.append(group_tag_item) new_group_tag = '&'.join(new_group_tag_list) else: new_group_tag = '' action = {'update':{'_id': uid}} bulk_action.extend([action, {'doc': {'group': new_group_tag}}]) if bulk_action: print 'bulk_action:', bulk_action es_user_portrait.bulk(bulk_action, index=portrait_index_name, doc_type=portrait_index_type) #step3: delete group results in group_manage try: print 'yes delete' result = es.delete(index=index_name, doc_type=index_type, id=task_id) except: return False return True
def delete_group_results(task_name): ''' query_body = { 'query':{ 'term':{ 'task_name': task_name } } } ''' #result = es.delete_by_query(index=index_name, doc_type=index_type, body=query_body) result = es.delete(index=index_name, doc_type=index_type, id=task_name) #print 'result:', result ''' if result['_indices']['twitter']['_shards']['failed'] == 0: return True else: return False ''' return True
def delete_group_results(task_name): try: result = es.delete(index=index_name, doc_type=index_type, id=task_name) except: return False return True
now_date = ts2datetime(now_ts) result['date'] = now_date es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name ,body=result) status = True return status # use to delete attribute def delete_attribute(attribute_name): status = False try: result = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] print 'result:', result except Exception, e: raise e return status es.delete(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name) print 'yes delete attribute' # delete attribute in user_portrait query = [] attribute_value = result['attribute_value'].split('&') for value in attribute_value: query.append({'match':{attribute_name: value}}) try: attribute_user_result = es.search(index=user_index_name, doc_type=user_index_type, \ body={'query':{'bool':{'must':query}}})['hits']['hits'] except: attribute_user_result = [] if attribute_user_result==[]: status = True return status bulk_action = []