创建索引

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. python去除文件中重复的行

    去除文件中重复的行 import os with open('db.txt','r',encoding='utf-8') as read_f,\ open('.db.txt.swap','w',enc ...

  2. sqlmap进阶篇—POST注入三种方法

    测试是否存在post注入 第一种方法 直接加--form让它自动加载表单 第二种方法 把form表单里面提交的内容复制出来,放到data中跑 第三种方法 先用burp suite抓包,把包的内容存到本 ...

  3. ecshop v2 v3 EXP

    import requests import binascii def get_v2Payload(code): '''Ecshop V2.x payload''' code = "{$ab ...

  4. 【java学习笔记2】访问控制修饰符 public、protected、默认、private

    先写了一个User()类: package chapter01; public class User { // 私有的 private int id; // 受保护的 protected int ag ...

  5. python之把列表当做队列使用

    把列表当做队列使用,只是在列表中第一个加入的元素,第一个提取出来,拿列表当做队列用,效率并不高.在列表中最后添加或者删除元素速度很快,然而从列表里插入或者从头弹出速度却不快,因为其他所有元素都要一个一 ...

  6. SpringBoot+Vue 前后端合并部署

    前后端分离开发项目 前端vue项目 服务端springboot项目 如何将vue的静态资源整合到springboot项目里,通过启动jar包的方式部署服务. 前端项目执行npm run build 命 ...

  7. js相关语法知识

    alert(); 页面弹窗 <input plactholder="请输入密码"/>(隐藏字体效果)js对数据类型不敏感,与Java相似1.js变量定义符:var2.j ...

  8. sprignAOP那些术语

    那些AOP术语 初看这么多术语,一下子都不好接受,慢慢来,很快就会搞懂.通知.增强处理(Advice) 就是你想要的功能,也就是上说的安全.事物.日志等.你给先定义好,然后再想用的地方用一下.包含As ...

  9. 盘点 Java 开发 2020 年发生的几件大事,你必须得知道!

    2021 年了,在过去的一年 Java 软件开发行业都发生了哪些重大事件呢? 这篇栈长带大家回顾一下,其实在元旦的<滚蛋吧,2020>也略有介绍,这篇就更加详细的总结一下. 1.Java ...

  10. Sqoop(二)常用命令及常数解析

    一.常用命令列举 二.命令及参数详解 1.数据库连接 2.import 3.export 4.hive