def count_hot_uid(uid, start_time, stop_time, keywords_list): query_body = { "query":{ "filtered":{ "filter":{ "bool":{ "must":[ {"range":{ "timestamp":{ "gte":start_time, "lt": stop_time } }}, {"term": {"root_uid": uid}} ] } } # "query":{ # "bool":{ # "should":[ # ] # } # } } } } if keywords_list: query_body['query']['filtered']['filter']['bool']['must'].append({"terms": {"keywords_string": keywords_list}}) #for word in keywords_list: #query_body['query']['filtered']['query']['bool']['should'].append({'wildcard':{"text": "*"+word+"*"}}) count = 0 datetime = ts2datetime(float(stop_time)) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count = 0 datetime_1 = ts2datetime(float(start_time)) if datetime_1 == datetime: pass else: ts = float(stop_time) while 1: ts = ts-day_time datetime = ts2datetime(ts) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count += 0 if datetime_1 == datetime: break return count
def count_hot_uid(uid, start_time, stop_time): query_body = { "query":{ "filtered":{ "filter":{ "bool":{ "must":[ {"range":{ "timestamp":{ "gte":start_time, "lt": stop_time } }}, {"term": {"root_uid": uid}} ] } } # "query":{ # "bool":{ # "should":[ # ] # } # } } } } count = 0 datetime = ts2datetime(float(stop_time)) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count = 0 datetime_1 = ts2datetime(float(start_time)) if datetime_1 == datetime: pass else: ts = float(stop_time) while 1: ts = ts-day_time datetime = ts2datetime(ts) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count += 0 if datetime_1 == datetime: break return count
def count_hot_uid(uid, start_time, stop_time): query_body = { "query": { "filtered": { "filter": { "bool": { "must": [{ "range": { "timestamp": { "gte": start_time, "lt": stop_time } } }, { "term": { "root_uid": uid } }] } } # "query":{ # "bool":{ # "should":[ # ] # } # } } } } count = 0 datetime = ts2datetime(float(stop_time)) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count = 0 datetime_1 = ts2datetime(float(start_time)) if datetime_1 == datetime: pass else: ts = float(stop_time) while 1: ts = ts - day_time datetime = ts2datetime(ts) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count += 0 if datetime_1 == datetime: break return count
def count_hot_uid(uid, start_time, stop_time, keywords_list): query_body = { "query":{ "filtered":{ "filter":{ "bool":{ "must":[ {"range":{ "timestamp":{ "gte":start_time, "lt": stop_time } }}, {"term": {"root_uid": uid}} ] } } # "query":{ # "bool":{ # "should":[ # ] # } # } } } } if keywords_list: full_text_dict = {"bool":{"should": []}} query_body['query']['filtered']['query'] = full_text_dict temp_list = [] for word in keywords_list: small_sentence = {"wildcard": {"text": {"wildcard": "*"+word+"*"}}} temp_list.append(small_sentence) query_body["query"]["filtered"]["query"]["bool"]["should"].extend(temp_list) count = 0 datetime = ts2datetime(float(stop_time)) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count = 0 datetime_1 = ts2datetime(float(start_time)) if datetime_1 == datetime: pass else: ts = float(stop_time) while 1: ts = ts-day_time datetime = ts2datetime(ts) index_name = flow_text_index_name_pre + datetime exist_es = es_text.indices.exists(index_name) if exist_es: count = es_text.count(index=index_name, doc_type=flow_text_index_type, body=query_body)["count"] else: count += 0 if datetime_1 == datetime: break return count