def delete_track_task(task_name):
    status = 0
    try:
        task_exist = es.get(index=index_name, doc_type=index_type, id=task_name)['_source']
    except:
        return 'task not exist'
    task_user = task_exist['uid_list']
    #change the user task_count in redis set
    #status = change_user_count(task_user)
    status = 1
    if status==0:
        return 'change user count fail'
    else:
        #delete task from es
        result = es.delete(index=index_name, doc_type=index_type, id=task_name)
        status = delete_task_redis(task_name)
        if status == 0:
            return 'delete task from redis fail'
        else:
            return 'success delete task'
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):
    '''
    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
Exemple #4
0
def delete_track_task(task_name):
    status = 0
    try:
        task_exist = es.get(index=index_name,
                            doc_type=index_type,
                            id=task_name)['_source']
    except:
        return 'task not exist'
    task_user = task_exist['uid_list']
    #change the user task_count in redis set
    #status = change_user_count(task_user)
    status = 1
    if status == 0:
        return 'change user count fail'
    else:
        #delete task from es
        result = es.delete(index=index_name, doc_type=index_type, id=task_name)
        status = delete_task_redis(task_name)
        if status == 0:
            return 'delete task from redis fail'
        else:
            return 'success delete task'
Exemple #5
0
    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
    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 = []