def submit_attribute(attribute_name, attribute_value, submit_user, submit_date):
    print "-----------submit_user---------"
    print submit_user
    status = False
    id_attribute = '-'.join([submit_user,attribute_name])
    print 'id_attribute:', id_attribute
    #maybe there have to identify the user admitted to submit attribute
    try:
        attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute)['_source']
    except:
        attribute_exist = {}
    #identify the tag name not same with the identify_attribute_list
    if attribute_exist == {} and id_attribute not in identify_attribute_list:
        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_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=id_attribute, body=input_data)
        status = True
        #put mappings to es_user_portrait
        submit_user_tag = str(submit_user) + "-tag"
        exist_field = es.indices.get_field_mapping(index=user_index_name, doc_type=user_index_type, field=submit_user_tag)
        if not exist_field:
            es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \
                body={'properties':{submit_user_tag:{'type':'string', 'analyzer':'my_analyzer'}}}, ignore=400)
    return status
Exemple #2
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
    try:
        attribute_exist = es_tag.get(index=attribute_index_name,
                                     doc_type=attribute_index_type,
                                     id=attribute_name)['_source']
    except:
        attribute_exist = {}
    #identify the tag name not same with the identify_attribute_list
    if attribute_exist == {} and attribute_name not in identify_attribute_list:
        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_tag.index(index=attribute_index_name,
                     doc_type=attribute_index_type,
                     id=attribute_name,
                     body=input_data)
        status = True
        #put mappings to es_user_portrait
        es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \
                body={'properties':{attribute_name:{'type':'string', 'index':'not_analyzed'}}}, ignore=400)
    return status
Exemple #3
0
def submit_attribute(attribute_name, attribute_value, submit_user,
                     submit_date):
    status = False
    id_attribute = '-'.join([submit_user, attribute_name])
    print 'id_attribute:', id_attribute
    #maybe there have to identify the user admitted to submit attribute
    try:
        attribute_exist = es_tag.get(index=attribute_index_name,
                                     doc_type=attribute_index_type,
                                     id=id_attribute)['_source']
    except:
        attribute_exist = {}
    #identify the tag name not same with the identify_attribute_list
    if attribute_exist == {} and id_attribute not in identify_attribute_list:
        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_tag.index(index=attribute_index_name,
                     doc_type=attribute_index_type,
                     id=id_attribute,
                     body=input_data)
        status = True
        #put mappings to es_user_portrait
        submit_user_tag = str(submit_user) + "-tag"
        exist_field = es.indices.get_field_mapping(index=user_index_name,
                                                   doc_type=user_index_type,
                                                   field=submit_user_tag)
        if not exist_field:
            es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \
                body={'properties':{submit_user_tag:{'type':'string', 'analyzer':'my_analyzer'}}}, ignore=400)
    return status
Exemple #4
0
def change_attribute(attribute_name, value, user, state):
    status = False
    # identify the attribute_name is in ES - custom attribute
    try:
        result =  es_tag.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_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name ,body=result)
    status = True
    return status
Exemple #5
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
    try:
        attribute_exist = es_tag.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source']
    except:
        attribute_exist = {}
    #identify the tag name not same with the identify_attribute_list
    if attribute_exist == {} and attribute_name not in identify_attribute_list:
        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_tag.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=input_data)
        status = True
        #put mappings to es_user_portrait
        es.indices.put_mapping(index=user_index_name, doc_type=user_index_type, \
                body={'properties':{attribute_name:{'type':'string', 'index':'not_analyzed'}}}, ignore=400)
    return status
Exemple #6
0
def change_attribute(attribute_name, value, user, state):
    status = False
    # identify the attribute_name is in ES - custom attribute
    try:
        result = es_tag.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_tag.index(index=attribute_index_name,
                 doc_type=attribute_index_type,
                 id=attribute_name,
                 body=result)
    status = True
    return status