from elasticsearch import Elasticsearch import json import time es = Elasticsearch(['es地址:9200'],ignore=[400, 405, 502]) def create_user(plat,gender,b_year,b_month,uni_ids = []): """增数据""" for uni_id in uni_ids: body = { "uni_id":uni_id, "customer_from_plat":plat, "gender":gender, "constellation":12, "birth_year":b_year, "birth_month":b_month, "state":"41", "city":"410300000000", "district":"410302000000", "email_suffix":"163.com", "customer_child":{ "name":"customer" } } print(body) es.index(index="index_customer_yangbo",doc_type="customer",id= uni_id,body=body) time.sleep(1) def del_date(ids=[]): """删数据""" for i in ids: es.delete(index="index_customer_yangbo", doc_type="customer", id=i) print(f"删除了_id为{i}的值") def sc_date(ids=[]): body = { "query":{ "terms":{ "_id":ids } } } res = es.search(index="index_customer_yangbo",body=body) #查询 print(json.dumps(res)) create_user("JOS","F","2019","11",["user20","user21","user22"]) #sc_date(["user20","user21","user22"]) #del_date(["user20","user21","user22"])