cd /opt
wget wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.0.0-linux-x86_64.tar.gz
useradd es
passwd es
chown -R es:root elasticsearch-7.0.0 更改所有者
su - es
cd /opt/elasticsearch-7.0.0/bin
./elasticsearch -d #启动 es , -d 表示后台运行
curl http://127.0.0.1:9200 # 测试
{
"name" : "iZ8vbdrp5nps3bwkpwyfuhZ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "wO8G-V8vRWa-JdX0QMPjYw",
"version" : {
"number" : "7.0.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "b7e28a7",
"build_date" : "2019-04-05T22:55:32.697037Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.7.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
使用
es 中? 的关键概念
索引:?类似关系型数据库中的表
文档:类似关系型数据库中 表的一条记录
创建索引
curl -H "Content-type:application/json" -XPUT http://127.0.0.1:9200/hotel -d '{"mappings":{"properties":{"title":{"type":"text"},"city":{"type":"keyword"},"price":{"type":"double"}}}}'
{"acknowledged":true,"shards_acknowledged":true,"index":"hotel"}
hotel 为 索引名称
创建文档 002 为id
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_doc/002 -d '{"title":"希尔顿酒店","city":"深圳市","price":1999.99}'
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_doc/007 -d '{"title":"希尔顿宾馆","city":"深圳市","price":79.99}'
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_doc/001 -d '{"title":"天上人间","city":"深圳市","price":299.99}'
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_doc/003 -d '{"title":"情侣酒店","city":"上海市","price":5999.99}'
搜索 id 为 001 的文档
curl http://127.0.0.1:9200/hotel/_doc/001
搜索 价格为 299.99的文档
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_search -d '{"query":{ "term":{"price":{"value":299.99}}}}'
摸糊搜索 title 希 的文档
curl -H "Content-type:application/json" -XPOST http://127.0.0.1:9200/hotel/_search -d '{"query":{ "match":{"title":"希"}}}'
给合 kibana7.0.0
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.0.0-linux-x86_64.tar.gz
tar -zxvf kibana-7.0.0-linux-x86_64.tar.gz
mv kibana-7.0.0-linux-x86_64 kibana-7.0.0
cd kibana-7.0.0/config
vim kibana.yml #修改配置
server.host: "0.0.0.0" # 外网可访问 kibana
elasticsearch.hosts: ["http://localhost:9200"] # es 地址
cd kibana-7.0.0/config/bin
./kibana & #启动
http://ip:56001 访问 kibana
|