BIG DATA

elastic search 명령어

코린이s 2022. 2. 20. 13:01
728x90

# 로그 건수 확인
GET servicelog-2022.02.20/_count
{
  "query": {
    "match_all": {}
  }
}
{
  "count" : 12,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}
# 로그 데이터별 건수 확인 (group by message.keyword)
GET servicelog-2022.02.20/_search
{
   "size": 0,
  "aggs": {
    "item": {
      "terms": {
        "field": "message.keyword"
      }
    }
  }
}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "item" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "{'name':'kafka'}",
          "doc_count" : 2
        },
        {
          "key" : "{'name':'logstash'}",
          "doc_count" : 2
        },
        {
          "key" : "{'name':'LeeHoSeong'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'LeeNow'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'ParkHyunJun'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'hongYooLee'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'horororo'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'nanigore'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'test'}",
          "doc_count" : 1
        },
        {
          "key" : "{'name':'thewayhj'}",
          "doc_count" : 1
        }
      ]
    }
  }
}

 

# 로그 유니크 건수
# - size : 0은 집계만 보겠다는 의미
# - aggs : 집계 사용 하겠다.
# - type_count : 집계 명칭으로 원하는 명칭을 사용하면 됩니다.
# - cardinality.field : 메세지의 값으로 집계를 하겠다.
# - cardinality.precision_threshold : es 의 집계 카운트는 대략적인 것으로 해당 수치를 올리면 메모리를
# 많이 차지 하지만 정확도는 올라간다. max : 40000 /default : 3000
POST servicelog-2022.02.20/_search
{
  "size": 0, 
  "aggs": {
    "type_count": {
      "cardinality": {
        "field": "message.keyword",
        "precision_threshold": 40000
      }
    }
  }
}
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "type_count" : {
      "value" : 10
    }
  }
}
# 제거
delete servicelog-2022.02.20

- 이미지 출처 : https://ko.m.wikipedia.org/wiki/%ED%8C%8C%EC%9D%BC:Elasticsearch_logo.svg

728x90