python |elasticsearchs操作es的例子
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"])
python |elasticsearchs操作es的例子的更多相关文章
- es的查询、排序查询、分页查询、布尔查询、查询结果过滤、高亮查询、聚合函数、python操作es
今日内容概要 es的查询 Elasticsearch之排序查询 Elasticsearch之分页查询 Elasticsearch之布尔查询 Elasticsearch之查询结果过滤 Elasticse ...
- Python基础篇【第2篇】: Python文件操作
Python文件操作 在Python中一个文件,就是一个操作对象,通过不同属性即可对文件进行各种操作.Python中提供了许多的内置函数和方法能够对文件进行基本操作. Python对文件的操作概括来说 ...
- 关于python 文件操作os.fdopen(), os.close(), tempfile.mkstemp()
嗯.最近在弄的东西也跟这个有关系,由于c基础渣渣.现在基本上都忘记得差不多的情况下,是需要花点功夫才能弄明白. 每个语言都有相关的文件操作. 今天在flask 的例子里看到这样一句话.拉开了文件操作折 ...
- Python之路Python文件操作
Python之路Python文件操作 一.文件的操作 文件句柄 = open('文件路径+文件名', '模式') 例子 f = open("test.txt","r&qu ...
- 彻底搞懂Python切片操作
在利用Python解决各种实际问题的过程中,经常会遇到从某个对象中抽取部分值的情况,切片操作正是专门用于完成这一操作的有力武器.理论上而言,只要条件表达式得当,可以通过单次或多次切片操作实现任 ...
- 关于python切片操作笔记
一. Python可切片对象的索引方式 包括:正索引和负索引两部分,如下图所示,以a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]为例: python索引方式.jpg 二. P ...
- Python“文件操作”Excel篇(上)
大家好,我们今天来一起探索一下用Python怎么操作Excel文件.与word文件的操作库python-docx类似,Python也有专门的库为Excel文件的操作提供支持,这些库包括xlrd.xlw ...
- 在Python中操作文件之truncate()方法的使用教程
在Python中操作文件之truncate()方法的使用教程 这篇文章主要介绍了在Python中操作文件之truncate()方法的使用教程,是Python入门学习中的基础知识,需要的朋友可以参考下 ...
- Python API 操作Hadoop hdfs详解
1:安装 由于是windows环境(linux其实也一样),只要有pip或者setup_install安装起来都是很方便的 >pip install hdfs 2:Client——创建集群连接 ...
随机推荐
- ROS 的一些常用命令行功能
1.安装并添加源sudo gedit /etc/apt/sources.list更新下sudo apt-get update添加 sources.list,如sudo sh -c '. /etc/ls ...
- send fd 无法传
string success = "1"; string urlstr = "http://localhost:8080/getfilecontent?filename= ...
- DOM是什么
UI—html—DOM(tree-structured representation. manipulate)—Virtual DOM(component) Real DOM强调树状结构的整体:核心是 ...
- Linux计划作业练习
1.crontab -eu zh //每天晚上10天提醒用户可以去睡觉了 * */10 * * * go to sleep 2.查询crontab的工作内容 3.当crontab命令格式出错时 ...
- C++的map用法
图,自动建立表示关键字和键值(key - value)之间的对应关系,两者可以是任何数据类型,key唯一并且自动排序,value不唯一. 1.头文件#include<map> 2.map& ...
- OpenCV 学习笔记(1-2)cuda8.0+cudnn安装
https://blog.csdn.net/qq_34199125/article/details/78352486 安装过程1.点击安装包一步一步安装即可.如果原来有cuda7.5,因此8.0安装后 ...
- learning shell check host dependent pkg
[Purpose] Shell script check host dependent pkg [Eevironment] Ubuntu 16.04 bash env ...
- 框架入门经典项目TodoMVC
一.项目介绍 ①地址:http://todomvc.com/ ②GitHub下载模板 ③通过npm下载模板的样式 ④通过npm下载Vuejs ⑤项目文件,主要修改app.js和index.html两个 ...
- SDOI 二轮垫底鸡
SDOI 二轮垫底鸡 day0 准备爆零 没啥好准备考试的,12.00出发,试机敲抄个ntt,在宾馆不知道颓啥. day1 爆零爬山 T1noip的题目也放到省选上. 第一档线段树?肯定不写,直接上1 ...
- HHHOJ #151. 「NOI模拟 #2」Nagisa
计算几何板子题(我才没有拷板子的说--) 众所周知,三角形的重心坐标是\((\frac{x_1+x_2+x_3}{3},\frac{y_1+y_2+y_3}{3})\) 然后我们发现如果我们有一个点集 ...