English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
집계 프레임워크는 검색 쿼리가 선택한 모든 데이터를 수집하고, 복잡한 데이터 요약을 구축하는 데 도움이 되는 많은 구성 요소로 구성되어 있습니다. 집계의 기본 구조는 다음과 같습니다:-
"aggregations" : { "" : { "" : { } [["meta" : { [] } ]? [["aggregations" : { []+ } } ["" : { ... } ]* }
집계는 여러 가지 유형이 있으며, 각 유형은 자신의 목적을 가집니다. 이 장에서는 이러한 문제들을 자세히 논의할 것입니다.
이러한 집계는 집계 문서의 필드 값에 따라 행렬을 계산하는 데 도움이 되며, 때로는 스크립트에서 몇 가지 값을 생성할 수 있습니다.
数值 행렬은 단일 값(예: 평균 집계) 또는 다중 값(예: 통계 데이터)일 수 있습니다.
이 집계는 집계 문서에 존재하는 모든 숫자 필드의 평균 값을 가져옵니다. 예를 들어:
POST /schools/_search { "aggs":{ "avg_fees":{"avg":{"field":"fees"}} } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 41, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : 1.0, "hits" : [ { "_index" : "schools", "_type" : "school", "_id" : "5", "_score" : 1.0, "_source" : { "name" : "Central School", "description" : "CBSE Affiliation", "street" : "Nagan", "city" : "paprola", "state" : "HP", "zip" : "176115", "location" : [ 31.8955385, 76.8380405 ], "fees" : 2200, "tags" : [ "Senior Secondary", "beautiful campus" ], "rating" : "3.3" } } { "_index" : "schools", "_type" : "school", "_id" : "4", "_score" : 1.0, "_source" : { "name" : "City Best School", "description" : "ICSE", "street" : "West End", "city" : "Meerut", "state" : "UP", "zip" : "250002", "location" : [ 28.9926174, 77.692485 ], "fees" : 3500, "tags" : [ "fully computerized" ], "rating" : "4.5" } } ] } "aggregations" : { "avg_fees" : { "value" : 2850.0 } } }
이 집계는 특정 필드의 다른 값을 세는 데 사용됩니다。
POST /schools/_search?size=0 { "aggs":{ "distinct_name_count":{"cardinality":{"field":"fees"}} } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 2, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "distinct_name_count" : { "value" : 2 } } }
Note 기초의 값은2가격이 두 가지 다른 값이 있기 때문에.
이 수집은 수집 문서에서 특정 숫자 필드의 모든 통계 정보를 생성합니다.
POST /schools/_search?size=0 { "aggs": { "fees_stats": { "extended_stats": { "field": "fees" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 8, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "fees_stats": { "count": 2, "min": 2200.0, "max": 3500.0, "avg": 2850.0, "sum": 5700.0, "sum_of_squares": 1.709E7, "variance": 422500.0, "std_deviation": 650.0, "std_deviation_bounds": { "upper": 4150.0, "lower": 1550.0 } } } }
이 수집은 수집 문서에서 특정 숫자 필드의 최대 값을 찾습니다.
POST /schools/_search?size=0 { "aggs": { "max_fees": { "max": { "field": "fees" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 16, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "max_fees": { "value" : 3500.0 } } }
이 수집은 수집 문서에서 특정 숫자 필드의 최소 값을 찾습니다.
POST /schools/_search?size=0 { "aggs": { "min_fees": { "min": { "field": "fees" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 2, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "min_fees" : { "value" : 2200.0 } } }
이 수집은 수집 문서에서 특정 숫자 필드의 합을 계산합니다.
POST /schools/_search?size=0 { "aggs": { "total_fees": { "sum": { "field": "fees" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 8, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "total_fees": { "value" : 5700.0 } } }
특정 경우에 지리적 경계 수집 및 지리적 중심 수집과 같은 다른 도메인 수집 표준화 규칙도 있습니다.
다중 값도메인 수집 표준화 규칙, 수집 문서에서 추출된 숫자를 기준으로 통계 정보를 계산할 수 있습니다.
POST /schools/_search?size=0 { "aggs": { "grades_stats": { "stats": { "field": "fees" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 2, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "grades_stats": { "count": 2, "min": 2200.0, "max": 3500.0, "avg": 2850.0, "sum": 5700.0 } } }
요청 시 meta 표시를 사용하여 추가적인 수집 데이터를 추가하고, 응답으로 사용할 수 있습니다.
POST /schools/_search?size=0 { "aggs": { "min_fees": { "avg": { "field": "fees" } }, "meta": { "dsc": "Lowest Fees This Year" } } } }
위의 코드를 실행할 때, 다음과 같은 결과를 얻었습니다.-
{ "took": 0, "timed_out": false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } "hits" : { "total" : { "value" : 2, "relation" : "eq" } "max_score" : null, "hits" : [ ] } "aggregations" : { "min_fees" : { "meta" : { "dsc" : "Lowest Fees This Year" } "value" : 2850.0 } } }