wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install elasticsearch
編輯配置文件:
/etc/elasticsearch/elasticsearch.yml
network.host: 127.0.0.1
network.bind_host: 127.0.0.1
transport.tcp.port: 9300
http.port: 9200
/usr/share/elasticsearch/bin/elasticsearch -d
ES中使用restful api對數據進行增刪查改
1)GET:查詢數據
2)POST:插入或更改數據
3)PUT:創建庫或表
4)DELETE:刪除庫
Index:數據庫
type:表
Document:行
Field:列,字段
Mapping:元信息
創建數據庫:http://localhost:9200/sinamail/ PUT
查看所有數據庫:http://localhost:9200/_cat/indices/ GET
刪除數據庫:http://localhost:9200/sinamail/ DELETE
舊版本創建表,並且定義字段:http://localhost:9200/sinamail/webmail/_mapping PUT
插入數據:
http://localhost:9200/sinamail/webmail/ POST
{
"accessLog": "測試一下"
}
查詢數據:
http://localhost:9200/sinamail/_search POST
{"query":{"bool":{"must":[{"match":{"accessLog":"測試下"}}]}},"from":0,"size":10}
使用CURL命令操作數據:
curl http://127.0.0.1:9200 查看狀態
curl -XPUT http://127.0.0.1:9200/sinamail 創建數據庫
curl http://127.0.0.1:9200/_cat/indices/ 查看所有數據庫
創建表,並且定義字段
curl -XPUT http://127.0.0.1:9200/sinamail/webmail/_mapping -d '{ "webmail": { "properties": { "accessLog": { "type": "string" } } } }'
插入數據
curl -XPOST http://127.0.0.1:9200/sinamail/webmail -d '{ "accessLog":"我是一個好人的測試" }'
查詢數據
curl -XPOST http://127.0.0.1:9200/sinamail/_search -d '{ "query":{ "bool":{ "must":[{"match":{"accessLog":"測我試下"}}]}},"from":0,"size":10 }'