: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

最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



