本章介紹
先備知識:
$docker-compose up -d
WARNING: Some services (elasticsearch, kibana) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Starting elasticsearch-624 ... done
Starting kibana-624 ... done
需要一點時間,可以用Kitematic之類的工具查看有沒有成功
確認elasticSearch是否啟動
確認kibana有無成功
{
"user": "user01",
"timestamp": 1583734521000,
"records": [
{
"record_name": "heart_rate",
"data_number": 80,
"data_txt": "avg"
},
{
"record_name": "Calories",
"data_number": 200
},
{
"record_name": "time_duration",
"data_number": 30,
"record_unit": "min"
}
]
}
PUT localhost:9200/event
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date",
"format": "epoch_millis"
},
"records": {
"type": "nested",
"properties": {
"record_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data_number": {
"type": "long",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data_txt": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"record_unit": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
介紹 kibana各個頁面使用
Management頁面->create index->填入event->選擇可以做時間分割的欄位名稱{上述是用timestamp}->按下create index pattern
再送一次資料,這次把 "timestamp": {改成現在時間戳}->線上有很多工具可以做轉換
回到Discover頁面,query最近15分鐘的資料->就可以看到時間軸了
ex: table顯示/長條圖顯示等/或是特定filter資料。然後替圖表存檔。
這邊把剛剛建立的圖表拉好顯示在這邊。
透過條件指令搜尋特定資料,如有程式需要可以用搜尋API試著找出自己想搜尋的內容
範例:
GET /event/_search
{
"size": 1000,
"query": {
"bool": {
"filter": {
"range": {
"timestamp": {
"from": 159132465000,
"include_lower": true,
"include_upper": true,
"to": 1591324650099
}
}
},
"must": [
{
"exists": {
"field": "user"
}
},
{
"match": {
"user": {
"operator": "AND",
"query": "user01"
}
}
},
{
"nested": {
"path": "records",
"query": {
"bool": {
"must": [
{
"match": {
"records.record_name": {
"operator": "AND",
"query": "heart_rate"
}
}
},
{
"wildcard": {
"records.data_txt": "*a*"
}
},
{
"range": {
"records.data_number": {
"from": 2,
"include_lower": false,
"include_upper": true,
"to": null
}
}
}
]
}
}
}
}
],
"minimum_should_match": "1",
"should": [
{
"match": {
"user": {
"operator": "AND",
"query": "user01"
}
}
},
{
"match": {
"user": {
"operator": "AND",
"query": "user02"
}
}
}
]
}
},
"sort": [
{
"timestamp": {
"order": "desc"
}
}
]
}
後續未解:elastic該如何建立cluster與管理??