Python Elasticsearch
以下所用版本为Elasticsearch 7.2.0
1.安装
pip3 install elasticsearch -i https://pypi.tuna.tsinghua.edu.cn/simple
2.连接ES
es = Elasticsearch([{'host': '127.0.0.1', 'port': 9200}])
3.创建index
index = 'index_tushare'
body = {
"mappings": {
"properties": {
"ts_code": {
"type": "keyword"
},
"symbol": {
"type": "keyword"
},
"ts_name": {
"type": "keyword"
},
"fullname": {
"type": "keyword"
},
"area": {
"type": "keyword"
},
"industry": {
"type": "keyword"
},
"list_date": {
"type": "keyword"
},
"tab_name": {
"type": "keyword"
}
}
}
}
# create an index in elasticsearch, ignore status code 400 (index already exists)
es.indices.create(index=index, body=body, ignore=400)
4.创建mapping之后,添加字段
index_daily_close = 'index_daily_close'
body_daily_close = {
"mappings": {
"properties": {
"trade_date": {
"type": "keyword"
}
}
}
}
es.indices.create(index=index_daily_close, body=body_daily_close, ignore=400) properties = body_daily_close.get("mappings").get("properties") def daily_close_add_tscodes(tscode):
properties.setdefault(tscode, {"type": "keyword"})
es.indices.put_mapping(index=index_daily_close, body=body_daily_close.get("mappings"))
print(body_daily_close.get("mappings"))
添加字段的时候要注意,elasticsearch默认最大字段数为1000,超过1000就会报错
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Limit of total fields [1000] in index [index_daily_close] has been exceeded"
}
],
"type": "illegal_argument_exception",
"reason": "Limit of total fields [1000] in index [index_daily_close] has been exceeded"
},
"status": 400
}
这里的1000是整个节点不能超过1000,我尝试了在多个索引里面添加字段,最终出现的结果是:

以上实验的方式是在第一个表中500个,然后第二个表中500个,在第998个的时候报错了。加上每个表本身有的 trade_date 字段,刚好加起来1000个。然后报错在了第1001个

Python Elasticsearch的更多相关文章
- Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据
Python Elasticsearch api 描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下 ...
- Python Elasticsearch api
描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下面介绍了利用Python API接口进行数据查询,方便 ...
- Python Elasticsearch批量操作客户端
基于Python实现的Elasticsearch批量操作客户端 by:授客 QQ:1033553122 1. 代码用途 1 2. 测试环境 1 3. 使用方法 1 3.1 配置ES服务器信息 1 ...
- python elasticsearch 批量写入数据
from elasticsearch import Elasticsearch from elasticsearch import helpers import pymysql import time ...
- Elasticsearch安装配置
文档地址: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/setup.html 官方页面提供自0.9版本以来的说明文档,由于我 ...
- django学习系列——python和php对比
python 和 php 我都是使用过,这里不想做一个非常理性的分析,只是根据自己的经验谈一下感想. 在web开发方面,无疑 php 更甚一筹. 从某种角度来说,php 就是专门为 web 定制的语言 ...
- ELK系列三:Elasticsearch的简单使用和配置文件简介
1.定义模板创建索引: 首先定义好一个模板的例子 { "order":14, "template":"ids-1", "state ...
- linux 安装elasticsearch
一.检测是否已经安装的elasticsearch ps aux|grep elasticsearch. 二.下载elasticsearch.tar.gz并上传至服务器usr/local/文件夹下 三. ...
- 工作笔记 之 Python应用技术
python socket编程详细介绍 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket,建立网络通信连接至少要一对端口号(socket). Socket本质是 ...
随机推荐
- 【JUC系列第三篇】-CAS算法详解
作者 : 毕来生 微信: 878799579 1.CAS是什么? CAS是英文单词(Compare-And-Swap)的缩写,中文意思是:比较并替换.CAS需要有3个操作数:内存地址V,旧的预期值A, ...
- 查找、AVL树、散列表
插值查找是二分查找的改进,斐波那契查找是插值查找的改进. 二分查找:mid=(low+high)/ 2 插值查找:mid=(key-a[low])*(high-low)/ (a[high]-a[l ...
- Codeforces Round #595 (Div. 3) A,B,C,D
A题:n个学生,分成任意组,要求每组中任意两名学生的技能值相差不等于1,问最小分组. #include<bits/stdc++.h> using namespace std; #defin ...
- python 版本及pip安装相关
python2与python3 由于历史原因,Python有两个大的版本分支,Python2和Python3,又由于一些库只支持某个版本分支,所以需要在电脑上同时安装Python2和Python3,因 ...
- bzoj 1996
区间 dp $f[i][j][1/0]$ 表示将理想数列的 $[i,j]$ 区间排好的方案数 $f[i][j][1]$ 表示最后进去的是第 $i$ 个人 $f[i][j][0]$ 表示最后进去的是第 ...
- CSP-S 模拟测试94题解
T1 yuuustu: 可以对两边取对数,然后就转化为两个double的比较,时间复杂度$O(n)$ 然后我就用神奇0.4骗分水过 #include<bits/stdc++.h> usin ...
- Docker实践--搭建Yapi测试平台
背景:项目需要选择不同测试平台,筛选一个最佳平台 现状:一台机器安装多套环境,虚拟机太繁琐 解决方案:通过Docker模拟安装测环境 参考:https://blog.csdn.net/qq_32447 ...
- MySQL优化:如何避免回表查询?什么是索引覆盖? (转)
数据库表结构: create table user ( id int primary key, name varchar(20), sex varchar(5), index(name) )engin ...
- Golang switch语句总结
switch 语句基本结构 switch 条件表达式 { case 常量表达式1: 语句 1 case 常量表达式2: 语句 2 . . . case 常量表达式n: 语句 n default: 语句 ...
- Promise初尝试
promise.ts export function showAlert() { console.log("开始调用showAlert"); return new Promise( ...