빅데이터/빅데이터기술
[빅데이터기술] Kibana에서 날짜를 기준으로 한 바 차트 생성
pbj0812
2020. 12. 29. 03:53
0. 목표
- Kibana에서 날짜를 기준으로 한 바 차트 생성
1. 데이터 삽입
1) library 호출
from elasticsearch import Elasticsearch
from elasticsearch import helpers
2) ES 연결
es = Elasticsearch('http://127.0.0.1:9200')
es.info()
3) 인덱스 생성 함수
def make_index(es, index_name):
if es.indices.exists(index=index_name):
es.indices.delete(index=index_name)
es.indices.create(index=index_name)
4) 날짜 생성
- ES에서 인덱스 생성시 자동으로 날짜 포맷으로 인식하기 위해 미리 datetime 형태로 넣어줌
from datetime import datetime
date1 = '12/26/20 10:12:13'
date2 = '12/26/20 10:13:13'
date3 = '12/27/20 10:12:13'
date4 = '12/27/20 10:12:13'
date5 = '12/27/20 10:12:13'
date6 = '12/28/20 10:12:13'
date7 = '12/28/20 11:12:13'
date8 = '12/28/20 12:12:13'
date9 = '12/28/20 13:12:13'
date10 = '12/28/20 14:12:13'
cre1 = datetime.strptime(date1, '%m/%d/%y %H:%M:%S')
cre2 = datetime.strptime(date2, '%m/%d/%y %H:%M:%S')
cre3 = datetime.strptime(date3, '%m/%d/%y %H:%M:%S')
cre4 = datetime.strptime(date4, '%m/%d/%y %H:%M:%S')
cre5 = datetime.strptime(date5, '%m/%d/%y %H:%M:%S')
cre6 = datetime.strptime(date6, '%m/%d/%y %H:%M:%S')
cre7 = datetime.strptime(date7, '%m/%d/%y %H:%M:%S')
cre8 = datetime.strptime(date8, '%m/%d/%y %H:%M:%S')
cre9 = datetime.strptime(date9, '%m/%d/%y %H:%M:%S')
cre10 = datetime.strptime(date10, '%m/%d/%y %H:%M:%S')
5) 데이터 제작
index_name = 'time_filtering2'
doc1 = {'word_text': '나는 소년 이다', 'Created': cre1}
doc2 = {'word_text': '나는 소년 이다', 'Created': cre2}
doc3 = {'word_text': '나는 소년 소녀 이다', 'Created': cre3}
doc4 = {'word_text': '나는 소녀 이다', 'Created': cre4}
doc5 = {'word_text': '나는 소년 이다', 'Created': cre5}
doc6 = {'word_text': '나는 소년 이다', 'Created': cre6}
doc7 = {'word_text': '나는 소년 소년 이다', 'Created': cre7}
doc8 = {'word_text': '나는 소년 이다', 'Created': cre8}
doc9 = {'word_text': '나는 소년 이다', 'Created': cre9}
doc10 = {'word_text': '나는 소녀 이다', 'Created': cre10}
6) 인덱스 생성
make_index(es, index_name)
7) 데이터 삽입
es.index(index=index_name, doc_type = 'log', body=doc1)
es.index(index=index_name, doc_type = 'log', body=doc2)
es.index(index=index_name, doc_type = 'log', body=doc3)
es.index(index=index_name, doc_type = 'log', body=doc4)
es.index(index=index_name, doc_type = 'log', body=doc5)
es.index(index=index_name, doc_type = 'log', body=doc6)
es.index(index=index_name, doc_type = 'log', body=doc7)
es.index(index=index_name, doc_type = 'log', body=doc8)
es.index(index=index_name, doc_type = 'log', body=doc9)
es.index(index=index_name, doc_type = 'log', body=doc10)
2. Kibana 설정
1) Manage
2) Index Patterns
3) Create index pattern
4) 해당 패턴 검색 및 Next step
5) Time filed 지정
6) Created 의 Type 확인(date)
7) Visualizations -> Create visualization
8) Vertical Bar
9) Buckets 을 X-axis 로 놓고 조작