es 安装
官网下载
https://www.elastic.co/cn/downloads/elasticsearch
下载好后,进入bin目录下,执行 ./elasticsearch
OQfNjlutv8.jpg
不报错,启动成功之后,就可以访问了http://localhost:9200/
但是页面就会出现让你输入账号密码,如下图
ntB5WVDc43.jpg
经过搜索,需要修改配置 config/elasticsearch.yml
cd5ZkFgFs7.jpg
接下来就可以正常访问啦!!!
KNFEcKeEAt.jpg
es head安装
下载地址 :https://github.com/mobz/elasticsearch-head
解压之后进行head文件夹下
cnpm run start
bVRL5QptLs.jpg
访问http://localhost:9100/ 就可以了
cgT0B018tQ.jpg
记得在config/elasticsearch.yml 添加两行
http.cors.enabled: true
http.cors.allow-origin: "*"
ES索引操作
创建不带mapping的索引
PUT /索引名
创建索引设置索引及分片
PUT /索引名
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 0
}
}
创建mapping (类似于schema)
这里补充一下es的数据类型吧!
es数据类型
PUT 索引名
{
{
"mappings":{
"properties":{
"id":{"type":"keyword"},
"content":{"type":"text"}
}
}
}
}