def delete_es(task_name): s_re = scan(es, query={ "query": { "match_all": {} }, "size": 1000 }, index=index_sensing_task, doc_type=task_name) bulk_action = [] count = 0 search_list = [] uid_list = [] while 1: try: uid = s_re.next()['_id'] count += 1 action = { "delete": { "_index": index_sensing_task, "_type": task_name, "_id": uid } } bulk_action.append(action) if count % 100 == 0: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) bulk_action = [] except StopIteration: print "all done" if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) break except Exception, r: print Exception, r
def delete_es(task_name): s_re = scan(es, query={"query":{"match_all":{}},"size":1000}, index=index_sensing_task, doc_type=task_name) bulk_action = [] count = 0 search_list = [] uid_list = [] while 1: try: uid = s_re.next()['_id'] count += 1 action = {"delete": {"_index": index_sensing_task, "_type": task_name, "_id": uid}} bulk_action.append(action) if count % 100 == 0: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) bulk_action = [] except StopIteration: print "all done" if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) break except Exception, r: print Exception, r
doc_type=task_name, timeout=60) bulk_action = [] except StopIteration: print "all done" if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) break except Exception, r: print Exception, r if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) print count return "1" if __name__ == "__main__": delete_es("律师群体言论".decode('utf-8')) delete_es("洪水灾情".decode('utf-8')) delete_es("民主言论".decode('utf-8')) delete_es("媒体感知社会事件".decode('utf-8'))
except: attribute_user_result = [] if attribute_user_result==[]: status = True return status bulk_action = [] for user_dict in attribute_user_result: try: user_item = user_dict['_source'] except: next user_item.pop(attribute_name) user = user_item['uid'] action = {'index':{'_id':str(user)}} bulk_action.extend([action, user_item]) es_user_portrait.bulk(bulk_action, index=user_index_name, doc_type=user_index_type) status = True return status # use to add attribute to user in es_user_portrait def add_attribute_portrait(uid, attribute_name, attribute_value, submit_user): status = False # identify the user exist # identify the attribute exist # identify the attribute exist in user_portrait # add attribute in user_portrait # submit user should has power to change???without try: user_result = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except:
while 1: try: uid = s_re.next()['_id'] count += 1 action = {"delete": {"_index": index_sensing_task, "_type": task_name, "_id": uid}} bulk_action.append(action) if count % 100 == 0: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) bulk_action = [] except StopIteration: print "all done" if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) break except Exception, r: print Exception, r if bulk_action: es.bulk(bulk_action, index=index_sensing_task, doc_type=task_name, timeout=60) print count return "1" if __name__ == "__main__": delete_es("律师群体言论".decode('utf-8')) delete_es("洪水灾情".decode('utf-8')) delete_es("民主言论".decode('utf-8')) delete_es("媒体感知社会事件".decode('utf-8'))