curl 是利用 URL 语法在命令行方式下工作的开源文件传输工具。
关于 curl 的介绍,参考官网:https://curl.haxx.se/
安装 curl
wget http://curl.haxx.se/download/curl-7.52.1.tar.gz
tar -zxf curl-7.52.1.tar.gz
cd curl-7.52.1
./configure -prefix=/usr/local/curl
make
make install
export PATH=$PATH:/usr/local/curl/bin
curl -V
curl 用法
https://curl.haxx.se/docs/manpage.html
# curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>
<REST Verb>:REST风格的语法谓词
<Node>:节点ip
<port>:节点端口号,默认9200
<Index>:索引名
<Type>:索引类型
<ID>:操作对象的ID号
对 Elasticsearch 操作(如查看 es 集群状态、节点、索引信息等)
curl '192.168.1.222:9200/_cat/health?v'
curl '192.168.1.222:9200/_cat/nodes?v'
curl '192.168.1.222:9200/_cat/indices?v'
导入案例数据 (官方下载地址:Loading Sample Data)
(官网下载可能较慢,另参考下载 Kibana Sample Data
在加载 Shakespeare 和logs 数据集之前需要映射(创建索引逻辑组), 参考 Mapping
curl -XPUT http://192.168.1.222:9200/shakespeare -d '
{
"mappings" : {
"_default_" : {
"properties" : {
"speaker" : {"type": "string", "index" : "not_analyzed" },
"play_name" : {"type": "string", "index" : "not_analyzed" },
"line_id" : { "type" : "integer" },
"speech_number" : { "type" : "integer" }
}
}
}
}
';
curl -XPUT http://192.168.1.222:9200/logstash-2015.05.18 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
curl -XPUT http://192.168.1.222:9200/logstash-2015.05.19 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
curl -XPUT http://192.168.1.222:9200/logstash-2015.05.20 -d '
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
完成后查看索引
> curl '192.168.1.222:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open bank vMe9pY2IQ6GayEp6YlDVOA 5 1 1000 0 666.6kb 666.6kb
yellow open logstash-2015.05.20 LAMCVpXXRLKxNJ10VJMsyA 5 1 4750 0 30.9mb 30.9mb
yellow open shakespeare PVDyOj2NT16d2_c5mfp66w 5 1 111396 0 29.6mb 29.6mb
yellow open logstash-2015.05.18 hu-In77qSzelQgnGnnacgA 5 1 4631 0 31.5mb 31.5mb
yellow open logstash-2015.05.19 Ee4WnAg_R1WuCz7XRF9DTg 5 1 4624 0 31.5mb 31.5mb
加载数据
curl -XPOST '192.168.1.222:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
curl -XPOST '192.168.1.222:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
curl -XPOST '192.168.1.222:9200/_bulk?pretty' --data-binary @logs.jsonl
浏览器访问: http://192.168.1.222:5601/ 创建3个索引匹配模式
ba*
shakes*
logstash-2015.05*
Kibana 安装参考:Elasticsearch 5.0 安装 kibana 5.0