python |elasticsearchs操作es的例子
2024-09-03 10:37:53
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":"",
"city":"",
"district":"",
"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","","",["user20","user21","user22"])
#sc_date(["user20","user21","user22"])
#del_date(["user20","user21","user22"])
最新文章
- HTML5标签
- java代码效率优化
- haproxy配置文件
- 极客DIY:制作一个可以面部、自主规划路径及语音识别的无人机
- Android简单图片浏览器
- BIEEE 创建多维钻取分析(4)
- LR监控Windows资源
- 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)
- centos系统python升级2.7.3
- trace openjdk from systemtap
- Java编程-第一个Java程序
- java与.net比较学习系列(6) 数组
- JAVA进阶----主线程等待子线程各种方案比较(转)
- cocoapods卸载重装 解决clone,install,search很慢的问题
- CentOS 7 yum install cobbler2.8.3
- spring中用到了哪些设计模式
- CCF2014032窗口(C语言)
- bzoj3879
- 阿里大于发送短信(java)
- wordpress主题升级之后返回到原来版本主题的方法