Elasticsearch + Kibana 起步
- 2019 年 10 月 6 日
- 筆記
下載Elasticsearch
下載地址 https://www.elastic.co/downloads
下載並解壓到 /usr/local/elasticsearch
啟動Elasticsearch
cd /usr/local/elasticsearch bin/elasticsearch
下載Kibana
下載地址 https://www.elastic.co/downloads
下載並解壓到 /usr/local/kibana
啟動Kibana
cd /usr/local/kibana bin/kibana
訪問Kibana
瀏覽器訪問http://localhost:5601 , 可以看的介面,說明配置正確。
在elasticsearch里創建一個template
創建文件/usr/local/scrapy.course-index-template.json, 內容如下
{ "mappings": { "_default_": { "_all": { "enabled": true, "norms": { "enabled": false } }, "dynamic_templates": [ { "strings_as_keywords": { "match_mapping_type": "string", "mapping": { "type": "keyword" } } }, { "unindexed_longs": { "match_mapping_type": "long", "mapping": { "type": "long", "index": false } } }, { "unindexed_doubles": { "match_mapping_type": "double", "mapping": { "type": "float", "index": false } } }, { "template1": { "mapping": { "doc_values": true, "ignore_above": 1024, "index": "not_analyzed", "type": "{dynamic_type}" }, "match": "*" } } ], "properties": { "title": { "type": "keyword" }, "subtitle": { "type": "text", "index": "analyzed" }, "url": { "type": "keyword" }, "status": { "type": "keyword" }, "price": { "type": "keyword" }, "rating": { "type": "integer" }, "ratingNum": { "type": "integer" }, "c_tags": { "type": "text", "index": "analyzed" }, "smallPicture": { "type": "keyword" }, "middlePicture": { "type": "keyword" }, "largePicture": { "type": "keyword" }, "about": { "type": "text", "index": "analyzed" }, "goals": { "type": "text", "index": "analyzed" }, "studentNum": { "type": "integer" }, "hitNum": { "type": "integer" }, "created": { "type": "date" }, "updated": { "type": "date" } } } }, "settings": { "index.refresh_interval": "5s" }, "template": "scrapy.course" }
導入template到elasticsearch
cd /usr/local curl -XPUT 'http://localhost:9200/_template/crapy.course?pretty' -d@scrapy.course-index-template.json
插入數據
進入kibana : http://localhost:5601, 選擇Dev Tools
在右側,輸入以下內容並點擊尖頭執行
put scrapy.course/normal/1 { "title":"Think in Java" }
查詢數據
Dev Tools 右側輸入一下命了,並執行
get scrapy.course/normal/1
執行結果
{ "_index": "scrapy.course", "_type": "normal", "_id": "1", "_version": 1, "found": true, "_source": { "title": "Think in Java" } }
說明索引創建成功。