본문 바로가기

Data Engineering/Cloud

[ELK스택] Elastic Search (3)

Metric Aggregation

산술 aggregation

{
    "size" : 0,
    "aggs" : {
        "stats_score" : {
                "stats" : {
                    "field" : "points"
            }
        }
    }
}
curl -XGET -H'Content-Type: application/json' localhost:9200/_search?pretty --data-binary @avg_points_aggs.json
  • AVG(평균)

  • MAX (최대값)

  • status : count/ min / max / avg / sum => aggregation이 다 나올 수 있는 코드


Bucket aggregation

SQL Group by와 같음

{
    "size" : 0,
    "aggs" : {
        "team_stats" : {
            "terms" : {
                "field" : "team"
            },
            "aggs" : {
                "stats_score" : {
                    "stats" : {
                        "field" : "points"
                    }
                }
            }
        }
    }
}
  • 일단 index 생성 후 mapping
curl -XPUT 'http://localhost:9200/basket/record/_mapping?include_type_name=true' -H "Content-Type: application/json" -d @basketball_mapping.json
  • document @file로 post하기
curl -XPOST 'localhost:9200/\_bulk' -H 'Content-Type: application/json' --data-binary @twoteam\_basketball.json
  • bucket aggregation search
curl -XGET -H "Content-Type: application/json" localhost:9200/basket/\_search?pretty --data-binary 
@terms\_aggs.json

team별로 document를 묶은 다음 결과값에서 또 aggregation을 진행함

 

index 조회

curl -XGET 'localhost:9200/\_cat/indices?v'

index 삭제

curl --location --request DELETE 'localhost:9200/basketbal'
 

[Elasticsearch] 기본 개념잡기

1. Elasticsearch란?Elasticsearch는 Apache Lucene( 아파치 루씬 ) 기반의 Java 오픈소스 분산 검색 엔진입니다.Elasticsearch를 통해 루씬 라이브러리를 단독으로 사용할 수 있게 되었으며, 방대한 양의 데이터를

victorydntmd.tistory.com

 

반응형

'Data Engineering > Cloud' 카테고리의 다른 글

[AWS] Claude2 token counting  (1) 2023.11.20
[AWS] Boto3로 S3 연결  (0) 2023.11.14
[ELK스택] Elastic Search (2)  (0) 2023.11.11
[ELK스택] Elastic Search (1)  (0) 2023.11.11
[AWS] S3 to RDS  (0) 2023.11.11