

GET kibana_sample_data_ecommerce/_search
{
"query": {
"match": {
"category": "clothing"
}
}
}
{
"took" : 25,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3927,
"relation" : "eq"
},
"max_score" : 0.20545526,
"hits" : [
{
GET kibana_sample_data_ecommerce/_search
{
"query": {
"bool": {
"filter": {
"term": {
"day_of_week": "Friday"
}
}
}
}
}
}
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 770,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
ElasticSearch에서 집계는 데이터를 그룹핑하고 통계값을 얻는 기능으로 SQL 의 GROUP BY 와 통계 함수를 포함하는 개념이다.
데이터를 날짜별로 묶거나 특정 카테고리별로 묶어 그룹별 통계를 내는 식이다.
키바나의 주 기능인 데이터 시각화와 대시보드는 대부분 집계 기능을 기반으로 동작한다.
집계를 위한 특별한 API가 제공되는 것은 아니며, search API 의 요청 본문에 aggs 파라미터를 이용하면 쿼리 결과에 대한 집계를 생성할 수 있다.
GET<인덱스>/_serach
{
"aggs": {
"aggs_type": {
'''
}
}
}
}
GET kibana_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"range_aggs": {
"range" : {
"field": "products.base_price",
"ranges": [
{ "from": 0, "to": 30 },
{ "from": 30, "to": 50 },
{ "from": 50, "to": 100 },
{ "from": 100, "to": 200 },
{ "from": 200, "to": 1000 }
]
}
}
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4675,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"range_aggs" : {
"buckets" : [
{
"key" : "0.0-30.0",
"from" : 0.0,
"to" : 30.0,
"doc_count" : 3882
},
{
"key" : "30.0-50.0",
"from" : 30.0,
"to" : 50.0,
"doc_count" : 1468
},
{
"key" : "50.0-100.0",
"from" : 50.0,
"to" : 100.0,
"doc_count" : 1902
},
{
"key" : "100.0-200.0",
"from" : 100.0,
"to" : 200.0,
"doc_count" : 263
},
{
"key" : "200.0-1000.0",
"from" : 200.0,
"to" : 1000.0,
"doc_count" : 13
}
]
}
}
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.17.1-linux-x86_64.tar.gz


input {
{ 입력 플러그인 }
filter {
{ 필터 플러그인 }
output {
{ 출력 플러그인 }
}
vi config/logstash-test.conf #
sudo ./bin/logstash -f config/logstash-test.conf
touch config/fillter-example.log
root@elastic:~/logstash-7.0.1# pwd
/root/logstash-7.0.1
root@elastic:~/logstash-7.0.1# cat config/logstash-test.conf
input {
file {
path => "/root/elasticsearch-7.0.1/logs/elasticsearch.log"
start_position => "beginning"
}
}
output {
stdout { }
}


--인풋 구조--
input{
file{
path => "/home/user1/logstashlab/config/fillter-example.log"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
--필터구조--
fillter{
mutate {
split => { "message" => " " }
add_field => { "id => %{[message][2]}" }
remove_field => "message"
}
}
--아웃풋 구조--
output{
stdout { }
}
실행결과
grok. loglevel은 모두다 대문자, 동일한 시간포맷으로 로그가 출력하자
input {
file {
path => "/home/user1/logstashlab/config/filter-example.log"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
dissect {
mapping => {"message" => "[%{timestamp}]%{?->}[%{id}] %{ip} %{+ip} [%{?level}] - %{}."}
}
date {
match => [ "timestamp", "YYYY-MM-dd HH:mm", "yyyy/MM/dd HH:mm:ss"]
target => "new_timestamp"
timezone => "UTC"
}
}
output {
stdout { }
elasticsearch {
hosts => ["211.183.3.10:9200"]
index => "2024-01-testlog"
}
}
[실행]
sudo ./bin/logstash -f config/logstash-test2.conf --log.level error
https://www.elastic.co/kr/elasticsearch