ElasticSearch Python 基本操作
创建索引
from elasticsearch import Elasticsearch
es = Elasticsearch('192.168.149.96:9200')
mappings = {
"mappings": {
"properties": {
"perName": {
"type": "keyword"
},
"schoolName": {
"type": "keyword"
},
"perGrade": {
"type": "double"
},
"position": {
"type": "keyword"
},
"proMonth": {
"type": "date", # 可以接受如下类型的格式
"format": "yyyy-MM"
},
"detailedTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"projectName": {
"type": "keyword"
},
"targetOutput": {
"type": "double"
},
"actualOutput": {
"type": "double"
},
"yieldReachingRate": {
"type": "double"
},
"lateness": {
"type": "double"
},
"overtime": {
"type": "double"
},
"workingHours": {
"type": "double"
},
"groupRanking": {
"type": "double"
},
"qualityInspection": {
"type": "double"
},
"numberOfCustomer": {
"type": "double"
}
}
}
}
result = es.indices.create(index='new_source', body=mappings)
print(result)
删除索引
from elasticsearch import Elasticsearch
es = Elasticsearch('192.168.149.96:9200')
result = es.indices.delete('production_data')
print(result)
插入数据
from elasticsearch import Elasticsearch
es = Elasticsearch('192.168.149.96:9200')
action = {
'perName': '张三',
'schoolName': '清华',
'perGrade': 101.0,
'position': '职务',
'proMonth': '2020-03',
'detailedTime': '2020-03-09 00:00:00',
'projectName': '画框转写',
'targetOutput': 100.0,
'actualOutput': 90.0,
'yieldReachingRate': 0.9,
'lateness': 1.0,
'overtime': 1.0,
'workingHours': 8.0,
'groupRanking': 3.0,
'qualityInspection': 2.0,
'numberOfCustomer': 1.0
}
result = es.index(index="source_data", body=action)
print(result)
批量插入时 action 给成列表, 遍历即可
查询所有数据
from elasticsearch import Elasticsearch
es_con = Elasticsearch([{'host': '192.168.149.96', 'port': 9200}])
data_agg = es_con.search(
index='base_data',
size=1000,
body={
"query": {
"match_all": {}
},
}
)
print(data_agg, '666666666')
for data in data_agg.get('hits').get('hits'):
list_data = data.get('_source')
if '' in list(list_data.values()):
print(list_data)
id_ = data.get('_id')
# es_con.delete(index='base_data', id=id_)
else:
pass
# print(list_data)
ElasticSearch Python 基本操作的更多相关文章
- Elasticsearch CRUD基本操作
前言 本次我们聊一聊Elasticsearch的基本操作CRUD,他跟我们常用的关系型数据库的操作又有什么不一样的地方呢?今天我们就来好好讲解一番. 说明 本次演示用的版本是7.11. 工具可以使用K ...
- Elasticsearch rest-high-level-client 基本操作
Elasticsearch rest-high-level-client 基本操作 本篇主要讲解一下 rest-high-level-client 去操作 Elasticsearch , 虽然这个客户 ...
- python对接elasticsearch的基本操作
基本操作 #!/usr/bin/env python # -*- coding: utf-8 -*- # author tom from elasticsearch import Elasticsea ...
- python基本操作
创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...
- Elasticsearch之基本操作
elasticsearch是一个是开源的(Apache2协议),分布式的,RESTful的,构建在Apache Lucene之上的的搜索引擎. 它有很多特点例如Schema Free,Document ...
- opencv python基本操作
Python usage crop frame: croppedframe = frame[ymin:ymax, xmin:xmax] resize frame: reszframe = cv2.re ...
- python基本操作(四)
与用户交互 为什么交互? 计算机取代人类,解放劳动力 如何交互 print('-'*100) input('请输入你的姓名:') print(""100) Python2和Pyth ...
- MongoDB与RoboMongo的安装+python基本操作MongoDB
MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是可以应用于各种规模的企业.各个行业以及各类应用程序的开源数据库.作为一个适用于敏捷开发的数据库,MongoDB的数据 ...
- mysql安装和简要操作命令+python基本操作mysql数据库
mysql数据库是一种关系型数据库管理系统. 一. windows平台安装Mysql数据库. Mysql数据库官网 :https://dev.mysql.com/downloads/windows/ ...
随机推荐
- Python利用openpyxl带格式统计数据(1)- 处理excel数据
统计数据的随笔写了两篇了,再来一篇,这是第三篇,前面第一篇是用xlwt写excel数据,第二篇是用xlwt写mysql数据.先贴要处理的数据截图: 再贴最终要求的统计格式截图: 第三贴代码: 1 '' ...
- Python字符串常用的一些东西
字符串的常用方法dir(str).查看某一方法的用法help(str.xxx). 1,索引和切片: 2,len():查看字符串的总长度. 3,+,拼接一个或多个字符串. 4,in,判定字符是否在字符串 ...
- Asp.Net Core仓储模式+工作单元
仓储模式+工作单元 仓储模式 仓储(Repository)模式自2004年首次作为领域驱动模型DDD设计的一部分引入,仓储本质上是提供提供数据的抽象,以便应用程序可以使用具有接口的相似的简单抽象集合. ...
- js Table表格选中一行变色或者多选 并获取值
使用JQ <script> let old, oldColor; $("#sp_body tr").click(function (i) { if (old) oldC ...
- C#中RDLC报表中日期显示格式
转换为日期类型再格式化 =CDate(Fields!UseDate.Value).ToString("yyyy-MM-dd") 使用Format ==Format(Fields!C ...
- asp.net url参数中有中文request.querystring 乱码
说明: 从这点我们发现:所有的参数输入,都调用了一次:HttpUtility.UrlDecode(str2, encoding); 结论出来了: 当客户端js对中文以utf-8编码提交到服务端时,用R ...
- [leetcode]508. Most Frequent Subtree Sum二叉树中出现最多的值
遍历二叉树,用map记录sum出现的次数,每一个新的节点都统计一次. 遍历完就统计map中出现最多的sum Map<Integer,Integer> map = new HashMap&l ...
- [leetcode33Search in Rotated Sorted Array]在排序旋转后序列中找目标值
直接上代码 /** * Created by lvhao on 2017/6/30. * Suppose an array sorted in ascending order is rotated a ...
- Android驱动学习-Eclipse安装与配置
在ubuntu系统下安装配置Eclipse软件.并且让其支持编译java程序和内核驱动程序. 1. 下载Eclipse软件. 打开官网:http://www.eclipse.org/ 点击 DOWN ...
- SSM框架实现多张图片和其他数据一起上传
一.SSM+Form 多张图片和其他数据一起上传, 1.导包: commons-fileupload-1.3.3.jar commons-io-2.4.jar 2.springmvc.xml 文件配置 ...