Пример #1
0
def change_attribute(attribute_name, value, user, state):
    status = False
    # identify the attribute_name is in ES - custom attribute
    try:
        result =  es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source']
    except:
        result = None
        return status
    value_list = '&'.join(value.split(','))
    result['attribute_name'] = attribute_name
    result['attribute_value'] = value_list
    result['user'] = user
    now_ts = time.time()
    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
Пример #2
0
def delete_attribute_portrait(uid, attribute_name, submit_user):
    status = False
    #identify the user exist
    #identify the attribute value exist in es_user_portrait
    #identify the submit_user have been admitted---without
    try:
        user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source']
    except:
        return 'no user'
    attribute_name = "tag-"+attribute_name
    if attribute_name not in user_exist:
        return 'user have no attribtue'
    try:
        del_attribute_value = user_exist.pop(attribute_name)
        es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_exist)
        status = True
    except Exception, e:
        raise e
Пример #3
0
def submit_attribute(attribute_name, attribute_value, submit_user, submit_date):
    status = False
    #maybe there have to identify the user admitted to submit attribute
    exist_bool = es.exists(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)
    if exist_bool:
        return "tag exists"
    else:
        input_data = dict()
        now_ts = time.time()
        date = ts2datetime(now_ts)
        input_data['attribute_name'] = attribute_name
        input_data['attribute_value'] = '&'.join(attribute_value.split(','))
        input_data['user'] = submit_user
        input_data['date'] = submit_date
        es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=input_data)

        submit_tag = "tag-" + attribute_name
        exist_field = es_user_portrait.indices.get_field_mapping(index=user_index_name, doc_type=user_index_type, field=submit_tag)
        if not exist_field:
            print es_user_portrait.indices.put_mapping(index=user_index_name, doc_type=user_index_type,body={'properties':{submit_tag:{'type':'string', 'analyzer':'my_analyzer'}}}, ignore=400)
        status = True
    print status
    return status