创建索引

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 基本操作的更多相关文章

  1. Elasticsearch CRUD基本操作

    前言 本次我们聊一聊Elasticsearch的基本操作CRUD,他跟我们常用的关系型数据库的操作又有什么不一样的地方呢?今天我们就来好好讲解一番. 说明 本次演示用的版本是7.11. 工具可以使用K ...

  2. Elasticsearch rest-high-level-client 基本操作

    Elasticsearch rest-high-level-client 基本操作 本篇主要讲解一下 rest-high-level-client 去操作 Elasticsearch , 虽然这个客户 ...

  3. python对接elasticsearch的基本操作

    基本操作 #!/usr/bin/env python # -*- coding: utf-8 -*- # author tom from elasticsearch import Elasticsea ...

  4. python基本操作

    创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...

  5. Elasticsearch之基本操作

    elasticsearch是一个是开源的(Apache2协议),分布式的,RESTful的,构建在Apache Lucene之上的的搜索引擎. 它有很多特点例如Schema Free,Document ...

  6. opencv python基本操作

    Python usage crop frame: croppedframe = frame[ymin:ymax, xmin:xmax] resize frame: reszframe = cv2.re ...

  7. python基本操作(四)

    与用户交互 为什么交互? 计算机取代人类,解放劳动力 如何交互 print('-'*100) input('请输入你的姓名:') print(""100) Python2和Pyth ...

  8. MongoDB与RoboMongo的安装+python基本操作MongoDB

        MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是可以应用于各种规模的企业.各个行业以及各类应用程序的开源数据库.作为一个适用于敏捷开发的数据库,MongoDB的数据 ...

  9. mysql安装和简要操作命令+python基本操作mysql数据库

    mysql数据库是一种关系型数据库管理系统.  一. windows平台安装Mysql数据库. Mysql数据库官网 :https://dev.mysql.com/downloads/windows/ ...

随机推荐

  1. Angular *ngIf length

    Angular *ngIf length 在Angular中如何判断*ngIf Arrary的长度? 具体代码如下: result = []; <div class="kt-secti ...

  2. 小题大做 | Handler内存泄露全面分析

    前言 嗨,大家好,问大家一个"简单"的问题: Handler内存泄露的原因是什么? 你会怎么答呢? 这是错误的回答 有的朋友看到这个题表示,就这?太简单了吧. "内部类持 ...

  3. [Python] iupdatable包:Status 模块使用介绍

    常用状态做的一个集合,方便用在函数返回值中区分不同状态结果. 简单举例: from iupdatable import Status def fun(): print("do somethi ...

  4. 解决Vue-router 报NavigationDuplicated的三种方法

    控制台会报[NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicate ...

  5. java中使用IO流将以文件中的内容去取到指定的文件中

    public class Demo12 { public static void main(String[] args) throws IOException { File file=new File ...

  6. hibernate连接数据库中文乱码

    4.做完这两步还是不行,需要修改hibernate的配置文件hibernate.cfg.xml,在配置文件配置hibernate.connection.url属性.示例: <property n ...

  7. 个人总结的一些C++基础理论

    我自己整理的一些C++基础理论知识,面试的同学可以用到: 主要是针对那些基础理论知识比较薄弱的同学吧,希望会对大家面试有些帮助,排版什么的有点乱,大家多多包涵: 往期经典: 北漂95后的2020 给北 ...

  8. editmd输出到前端显示

    官方案例:html-preview-markdown-to-html.html 输出后台数据显示在前端,格式化内容<!DOCTYPE html> <html lang="z ...

  9. Daphile 安装手册 -- 官方文档译文 [原创]

    Daphile 安装手册(Daphile Installation) 英文原文:https://www.daphile.com/download/DaphileInstallation.pdf 采集日 ...

  10. JVM笔记——类加载

    1.在java代码中,类型(如class enum interface)的加载.连接.初始化过程都是在程序运行期完成的.这个特性,使得本为静态语言的java,拥有了动态语言的某些特征 加载:查找并加载 ...