1.安装Elasticsearch
(略)
2.下载elasticsearch-head
3.安装grunt
npm install -g grunt-cli
4.解压elasticsearch-head
cd 到解压后的目录下,执行 npm install
5.修改elasticsearch.yml 配置文件
新增
http.cors.enabled: true
http.cors.allow-origin: "*"
6.修改elasticsearch-head-master/Gruntfile.js文件
connect: {
server: {
options: {
hostname: '192.168.9.108',
port: 9100,
base: '.',
keepalive: true
}
}
}
7. 在elasticsearch-head-master目录下启动elasticsearch-head
运行命令
grunt server
8.通过浏览器连接http://192.168.9.108:9100/
image.png
9.新加节点,看看效果
bootstrap.memory_lock: false
cluster.name: elasticsearch_zhang
http.port: 9200
node.data: true
node.ingest: true
node.master: true
node.max_local_storage_nodes: 1
node.name: DESKTOP-V8P04QS
path.data: C:\Users\user\Elastic\Elasticsearch\data
path.logs: C:\Users\user\Elastic\Elasticsearch\logs
transport.tcp.port: 9300
network.host: [_local_, 192.168.9.101]
discovery.zen.ping.unicast.hosts: ["192.168.9.108:9300"]
启动节点后,浏览器查看
image.png
10.执行批量插入后,节点变化
from elasticsearch import Elasticsearch
from datetime import datetime
es = Elasticsearch(hosts=["192.168.9.108"])
s = es.bulk(
index="website",
doc_type="blog",
body=[
# {action: metadata}
{"create": {"_id": 8}},
# {request body}
{
"title": "created using es.bulk",
"date": datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
"text": "try to write a doc to es"
},
# {action: metadata}
{"create": {"_id": 19}},
# {request body}
{
"title": "created using es.bulk",
"date": datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
"text": "try to write a doc to es"
}
]
)
image.png
网友评论