文章目录
学习目标:
- window10系统安装Elasticsearch。
- window10 系统安装 kibana
- python的简单交互使用Elasticsearch
学习内容:
0、需要先安装java,
这个安装参考菜鸟教程吧
或者自行百度,因为我之前安装的有java环境了。
1. window10系统安装Elasticsearch。
1)、下载压缩包

2)、解压执行。

-
解压放到一个指定的地方。
-
运行解压包中
bin\elasticsearch.bat

到这里之后,可以了
出现下面的界面就代表安装成功了。

2、安装Kibana
0、需要安装nodejs:
因为Kibana是基于nodejs的,需要安装nodejs
这个下载安装exe即可。
1)、下载压缩包

2)、 解压运行:

-
和刚刚安装的elasticsearch解压同一个目录下就行。
-
直接点击运行
bin\kibana.bat等待一会即可: -
访问http://localhost:5601
进来之后这个就可以了。

3、python与elasticsearch的交互:
这个需要安装并运行elasticsearch。
1)、安装模块elasticsearch

安装成功。
2)、增加数据
from elasticsearch import Elasticsearch
# 默认host为localhost,port为9200.但也可以指定host与port
es = Elasticsearch()
# 添加或更新数据,index,doc_type名称可以自定义,id可以根据需求赋值,body为内容
es.index(index="my_index",doc_type="test_type",id=1,body={"name":"python","addr":"深圳21"})
# 或者:ignore=409忽略文档已存在异常
# es.create(index="my_index",doc_type="test_type",id=1,ignore=409,body={"name":"python","addr":"深圳2"})
es.create(index="my_index",doc_type="test_type",id=3,ignore=409,body={"name":"python","addr":"深圳2"})
3)、查询:
from elasticsearch import Elasticsearch
es = Elasticsearch()
# 获取索引为my_index,文档类型为test_type的所有数据,result为一个字典类型
result = es.search(index="my_index",doc_type="test_type")
# 或者这样写:搜索id=1的文档
# result = es.get(index="my_index",doc_type="test_type",id=1)
print("result",type(result),result)
# 打印所有数据
for item in result["hits"]["hits"]:
print(item["_source"])
3)、删除数据:
from elasticsearch import Elasticsearch
es = Elasticsearch()
# 删除id=1的数据
result = es.delete(index="my_index",doc_type="test_type",id=1)
310



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



