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/ ...
随机推荐
- java基础:进制详细介绍,进制快速转换,二维数组详解,循环嵌套应用,杨辉三角实现正倒直角正倒等腰三角,附练习案列
1.Debug模式 1.1 什么是Debug模式 是供程序员使用的程序调试工具,它可以用于查看程序的执行流程,也可以用于追踪程序执行过程来调试程序. 1.2 Debug介绍与操作流程 如何加断点 选择 ...
- wildfly 21中应用程序的部署
目录 简介 Managed Domain中的部署 管理展开的部署文件 standalone模式下的部署 standalone模式下的自动部署 Marker Files 受管理的和不受管理的部署 部署覆 ...
- eclipse 再见,android studio 新手入门教程(三)Github(ignore 忽略规则)的使用
上传代码到github android studio里集成了上传代码到github的功能,所以使用上还是很简单的,设置里添加账号并测试,之后就可以很方便地上传代码到github了 如果你的项目是使用a ...
- 算法(Java实现)—— 贪心算法
贪心算法 应用场景-集合覆盖问题 假设在下面需要付费的广播台,以及广播台新型号可以覆盖的地区,如何选择最少的广播台,让所有地区都可以接收到信号 广播台 覆盖地区 k1 北京.上海.天津 k2 广州.北 ...
- 使用freetype来显示中文汉字和英文字符
这里我们用到了freetype.进入官网http://savannah.nongnu.org/download/freetype/ 中下载最新的版本2.7的源代码和文件.freetype-2.7.ta ...
- 学习Promise异步编程
JavaScript引擎建立在单线程事件循环的概念上.单线程( Single-threaded )意味着同一时刻只能执行一段代码.所以引擎无须留意那些"可能"运行的代码.代码会被放 ...
- JavaDailyReports10_16
今天学习安装配置了JavaWeb的资源环境, 明天开始学习HTML!
- Centos7 安装Teamviewer
参考:链接1 链接2 链接3 由于工作原因,需要再Centos7.6下安装Teamviewer,流程如下: 下载 TeamViewer下载 链接 wget https://download.tea ...
- mysql8.0.x中datasource信息
driverClassName: com.mysql.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourceurl: jdbc:mysql:// ...
- TurtleBot3 Waffle (tx2版华夫)(11)建图-karto建图
1)[Remote PC] 启动roscore $ roscore 2)[TurBot3] 启动turbot3 $ roslaunch turbot3_bringup minimal.launch 3 ...