當前位置: 首頁>>代碼示例>>Python>>正文


Python ES_CLUSTER_FLOW1.search方法代碼示例

本文整理匯總了Python中user_portrait.global_utils.ES_CLUSTER_FLOW1.search方法的典型用法代碼示例。如果您正苦於以下問題:Python ES_CLUSTER_FLOW1.search方法的具體用法?Python ES_CLUSTER_FLOW1.search怎麽用?Python ES_CLUSTER_FLOW1.search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在user_portrait.global_utils.ES_CLUSTER_FLOW1的用法示例。


在下文中一共展示了ES_CLUSTER_FLOW1.search方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search_top_index

# 需要導入模塊: from user_portrait.global_utils import ES_CLUSTER_FLOW1 [as 別名]
# 或者: from user_portrait.global_utils.ES_CLUSTER_FLOW1 import search [as 別名]
def search_top_index(index_name, top_k=1, index_type="bci", top=False, sort_order="user_index"):
    query_body = {
        "query": {
            "match_all": {}
        },
        "size": top_k,
        "sort": [{sort_order: {"order": "desc"}}]
    }

    if top:
        result = es.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits'][0]['_source'][sort_order]
    else:
        search_result = es.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits']

        uid_list = []
        for item in search_result:
            uid_list.append(item['_id'])
        profile_result = es_profile.mget(index="weibo_user",doc_type="user", body={"ids":uid_list}, _source=True)['docs']
        portrait_result = es_portrait.mget(index="user_portrait", doc_type="user", body={"ids":uid_list}, _source=True)['docs']

        result = []
        rank = 1
        for i in range(len(search_result)):
            info = ['','','','']
            info[0] = rank
            if profile_result[i]['found']:
                info[1] = profile_result[i]['_source'].get('photo_url','')
                info[3] = profile_result[i]['_source'].get('nick_name','')

            info[2] = search_result[i].get('_id','')
            if sort_order in ["user_index","origin_weibo_retweeted_brust_average","origin_weibo_comment_brust_average"]:
                info.append(search_result[i]['_source'][sort_order])
                if portrait_result[i]['found']:
                    info.append("1")
                else:
                    info.append("0")
            elif sort_order == "origin_weibo_retweeted_top_number":
               info.append(search_result[i]['_source']['origin_weibo_retweeted_top_number']) 
               mid = search_result[i]['_source']['origin_weibo_top_retweeted_id']
               info.append(weiboinfo2url(info[2],mid))
               if portrait_result[i]['found']:
                   info.append("1")
               else:
                   info.append("0")
            elif sort_order == "origin_weibo_comment_top_number":
                info.append(search_result[i]['_source']['origin_weibo_comment_top_number'])
                mid = search_result[i]['_source']['origin_weibo_top_comment_id']
                info.append(weiboinfo2url(info[2],mid))
                if portrait_result[i]['found']:
                    info.append("1")
                else:
                    info.append("0")

            rank += 1
            result.append(info)

    return result
開發者ID:ztybuaa,項目名稱:user_portrait,代碼行數:59,代碼來源:search_user_index_function.py

示例2: query_brust

# 需要導入模塊: from user_portrait.global_utils import ES_CLUSTER_FLOW1 [as 別名]
# 或者: from user_portrait.global_utils.ES_CLUSTER_FLOW1 import search [as 別名]
def query_brust(index_name,field_name, range_1=0, range_2=50000, count=0):
    query_body = {
        "query":{
            "filtered": {
                "query": {
                    "match_all":{}
                },
                "filter": {
                    "range": {
                        field_name: {
                            "gte": range_1,
                            "lt": range_2
                        }
                    }
                }
            }
        }
    }

    if count == 1:
        result = es.count(index=index_name, doc_type="bci", body=query_body)['count']
        return result

    else:
        query_body['size'] = 1000
        result = es.search(index=index_name, doc_type="bci", body=query_body)['hits']['hits']

        profile_list = []
        for item in result:
            profile_list.append(item['_id'])

        return profile_list
開發者ID:ztybuaa,項目名稱:user_portrait,代碼行數:34,代碼來源:search_user_index_function.py

示例3: search_portrait_history_active_info

# 需要導入模塊: from user_portrait.global_utils import ES_CLUSTER_FLOW1 [as 別名]
# 或者: from user_portrait.global_utils.ES_CLUSTER_FLOW1 import search [as 別名]
def search_portrait_history_active_info(uid, date, index_name="copy_user_portrait", doctype="user"):
    # date.formate: 20130901
    date_list = time_series(date)

    try:
        result = es.get(index=index_name, doc_type=doctype, id=uid, _source=True)['_source']
    except NotFoundError:
        return "NotFound"
    except:
        return None
    
    date_max = {}
    for date_str in date_list:
        query_body = {
            'query':{
                'match_all':{}
                },
            'size': 1,
            'sort': [{date_str: {'order': 'desc'}}]
        }
        try:
            max_item = es.search(index=index_name, doc_type=doctype, body=query_body)['hits']['hits']
        except Exception, e:
            raise e
        date_max[date_str] = max_item[0]['_source'][date_str]
開發者ID:taozhiiq,項目名稱:user_portrait,代碼行數:27,代碼來源:search_user_index_function.py

示例4: search_k

# 需要導入模塊: from user_portrait.global_utils import ES_CLUSTER_FLOW1 [as 別名]
# 或者: from user_portrait.global_utils.ES_CLUSTER_FLOW1 import search [as 別名]
def search_k(es, index_name, index_type, start, field="user_index", size=100):
    query_body = {
        "query":{
            "match_all": {}
            },
        "size": size,
        "from": start,
        "sort": [{field: {"order": "desc"}}]
    }

    result = es.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits']

    search_list = []
    for item in result:
        search_list.append(item['_source'])

    return search_list
開發者ID:ferrero-zhang,項目名稱:user_portrait_0324,代碼行數:19,代碼來源:rank_portrait_in_active_user.py

示例5: get_evaluate_max

# 需要導入模塊: from user_portrait.global_utils import ES_CLUSTER_FLOW1 [as 別名]
# 或者: from user_portrait.global_utils.ES_CLUSTER_FLOW1 import search [as 別名]
def get_evaluate_max(index_name):
    max_result = {}
    index_type = 'bci'
    evaluate_index = ['user_index']
    for evaluate in evaluate_index:
        query_body = {
            'query':{
                'match_all':{}
                },
            'size':1,
            'sort':[{evaluate: {'order': 'desc'}}]
            }
        try:
            result = es_cluster.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits']
        except Exception, e:
            raise e
        max_evaluate = result[0]['_source'][evaluate]
        max_result[evaluate] = max_evaluate
開發者ID:ferrero-zhang,項目名稱:user_portrait_0324,代碼行數:20,代碼來源:utils.py


注:本文中的user_portrait.global_utils.ES_CLUSTER_FLOW1.search方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。