以下所用版本为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的更多相关文章

  1. Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据

    Python Elasticsearch api   描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下 ...

  2. Python Elasticsearch api

    描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下面介绍了利用Python API接口进行数据查询,方便 ...

  3. Python Elasticsearch批量操作客户端

    基于Python实现的Elasticsearch批量操作客户端 by:授客 QQ:1033553122   1. 代码用途 1 2. 测试环境 1 3. 使用方法 1 3.1 配置ES服务器信息 1 ...

  4. python elasticsearch 批量写入数据

    from elasticsearch import Elasticsearch from elasticsearch import helpers import pymysql import time ...

  5. Elasticsearch安装配置

    文档地址: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/setup.html 官方页面提供自0.9版本以来的说明文档,由于我 ...

  6. django学习系列——python和php对比

    python 和 php 我都是使用过,这里不想做一个非常理性的分析,只是根据自己的经验谈一下感想. 在web开发方面,无疑 php 更甚一筹. 从某种角度来说,php 就是专门为 web 定制的语言 ...

  7. ELK系列三:Elasticsearch的简单使用和配置文件简介

    1.定义模板创建索引: 首先定义好一个模板的例子 { "order":14, "template":"ids-1", "state ...

  8. linux 安装elasticsearch

    一.检测是否已经安装的elasticsearch ps aux|grep elasticsearch. 二.下载elasticsearch.tar.gz并上传至服务器usr/local/文件夹下 三. ...

  9. 工作笔记 之 Python应用技术

    python socket编程详细介绍 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket,建立网络通信连接至少要一对端口号(socket). Socket本质是 ...

随机推荐

  1. 表达式* ptr ++和++ * ptr是否相同?

    两种表达都不同.让我们看一个示例代码来理解两个表达式之间的区别.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h>   int m ...

  2. VS 项目清理小工具 ClearSolution

    简介 VS项目清理小工具,通过INI配置文件快速清理项目,清除无用的数据库等文件与文件夹,简单实用. 支持平台 Windows 开源许可 ClearSolution 遵循 [Apache 协议],使用 ...

  3. IE版本判断条件注释

    IE下判断IE版本的语句...[if lte IE 8]……[endif]  <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见   < ...

  4. 后代元素 span:first-child{...}

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  5. poj 2762

    Tarjan + TopsortTarjan 缩点Topsort 判断 Topsort 判断:在DAG中若初始状态下存在多于1个入度为0的点则说明这些 入度为0的点之间不会有路径可达若不存在入度为0的 ...

  6. error while loading shared libraries: libmysqlclient.so.20 问题小结

    问题:安装完成sysbench之后,查看sysbench版本号时出现下面问题.这种报错很常见, [root@zero01 sysbench]# /usr/local/sysbench/bin/sysb ...

  7. CentOS 7.5 ——如何开放80、8080、3306等端口

    CentOS 7.5 ——如何开放80.8080.3306等端口 ——说明:CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙——1.关闭firewall: s ...

  8. 解决百度文字识别SDK拍照不回调问题

    在使用百度文字识别SDK的时候,发现点了拍照后camera.takePicture(ShutterCallback shutter, PictureCallback raw,PictureCallba ...

  9. 服务器 Web服务器 应用服务器区别联系

    服务器: 通俗的讲,我们访问一个网站就相当于访问一个服务器的文件,如果想要通过自己的域名来访问一个网站,首先得将域名部署到你的服务器上,然后就可以通过域名访问到你服务器上的网 页文件.ip地址就相当于 ...

  10. spring项目启动错误——java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

    最近在搭spring项目框架的时候,遇到一个很伤的问题,翻了很多帖,都报告说什么少spring-context包啊之类的,但实际上spring的那些依赖我根本没漏,下面是我的pom: <depe ...