0、准备开启数据库
① 关闭Linux防火墙,这个很重要,否则API总是报错连不上。
# 查看防火墙状态
firewall-cmd --state# 关闭防护墙
systemctl stop firewalld.service# 开启防火墙
systemctl start firewalld.service# 重启防火墙
systemctl restart firewalld.service# 禁止firewalld开机启动
systemctl disable firewalld.service
② 启动elasticsearch
bin/elasticsearch
③ 启动Kibana
bin/kibana
1、使用conda或者pip安装elasticsearch 6.1.1
# 使用conda
conda install elasticsearch=6.1.1#使用pip
pip install elasticsearch==6.1.1
2、主要的Python代码
# -*- coding: utf-8 -*-
from elasticsearch import Elasticsearchif __name__ == '__main__':es = Elasticsearch(['192.168.1.211'], http_auth=('elastic', '5tgbhu8'), port=9200)index = "my_index"dtype = "my_type"mappings = \{dtype: {"include_in_all": False,"properties": {"A": {"type": "nested","properties": {"A1": {"type": "keyword"},"A2": {"type": "long"}}},"B": {"type": "nested","properties": {"B1": {"type": "keyword"},"B2": {"type": "long"}}}}}}body = {"ThemeCount": [{"A1": "file","A2": 35},{"A1": "root","A2": 45}],"B": [{"B1": "work","B2": 56},{"B1": "etc","B2": 88}]}if es.indices.exists(index=index):es.indices.delete(index=index)es.indices.create(index=index)# 设置mappinges.indices.put_mapping(doc_type=dtype, body=mappings, index=index)es.index(index=index, doc_type=dtype, body=body)
3、使用Kibana查看结果
# 在浏览器中打开
http://192.168.1.211:5601# Dev tools
GET /my_index/_search