python 批量写入es

:w1环境

pyhont2.7

elasticsearch 5.6.8

es客户端(python插件)。6.4.0     https://pypi.org/simple/elasticsearch/ 可查询可安装的es客户端包

pip install elasticsearch 是安装的最新包。。后面运行会报错。。不兼容。。。只能指定版本安装

pip install elasticserach==6.4.0

2脚本

import time
from elasticsearch import Elasticsearch
from elasticsearch import helpers
ES = ['127.0.0.1:9200']
es = Elasticsearch(ES)

def timer(func):
    def wrapper(*args, **kwargs):
        start = time.time()
        res = func(*args, **kwargs)
        return res

    return wrapper
@timer
def gen():
    action = ({
        "_index": "s2",
        "_type": "doc",
        "_source": {
            "title": i
        }
    } for i in range(100000))
    helpers.bulk(es, action)

if __name__ == '__main__':
    # create_data()
    # batch_data()
    gen()

3查询数据

curl http://127.0.0.1:9200/s2/_search?pretty -d '{"query": {"match":{"title":{"query": "7343"}}}}'   查询title   为7343的数据  title为字段

curl http://127.0.0.1:9200/s2/_search?pretty -d '{"query": {"match_all":{}}}'查询所有数据。。但是不会显示完。。。

Es常用查询命令

1查集群状态

Curl http://127.0.0.1:9200/_cat/health?

Curl http://127.0.0.1:9200/_cluster/h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值