Ejemplo n.º 1
0
def count_maxweibouser_influence(end_time):
    date_time = ts2datetimestr(end_time)
    index_name = weibo_bci_index_name_pre + date_time
    print 'max index_name:', index_name
    query_body = {
        'query': {
            'match_all': {}
        },
        'size': 1,
        'sort': {
            'user_index': {
                'order': 'desc'
            }
        }
    }
    try:
        #if S_TYPE == 'test':
        #    temp_index_name='bci_20161121'
        #    max_result=es_user_profile.search(index=temp_index_name,doc_type=weibo_bci_index_type,body=query_body)['hits']['hits']
        #else:
        max_result = es_user_profile.search(index=index_name,
                                            doc_type=weibo_bci_index_type,
                                            body=query_body)['hits']['hits']
        for item in max_result:
            max_user_index = item['_source']['user_index']
    except:
        max_user_index = 1
    return max_user_index
Ejemplo n.º 2
0
def count_weibouser_weibosum(uid, end_time):
    date_time = ts2datetimestr(end_time - DAY)
    index_name = xnr_flow_text_index_name_pre + date_time

    query_body = {
        'query': {
            'filtered': {
                'filter': {
                    'term': {
                        'uid': uid
                    }
                }
            }
        },
        'size': 1,
        'sort': {
            'timestamp': {
                'order': 'desc'
            }
        }
    }
    try:
        weibo_result = es_xnr.search(index=index_name,
                                     doc_type=xnr_flow_text_index_type,
                                     body=query_body)['hits']['hits']
        for item in weibo_result:
            weibos_sum = item['_source']['weibos_sum']
    except:
        weibos_sum = 0
    return weibos_sum