이것은 terms
집계 (documentation)의 일이다.
이 같은 별개의 departments
값을 가질 수 있습니다
POST company/employee/_search
{
"size":0,
"aggs": {
"by_departments": {
"terms": {
"field": "departments.name",
"size": 0 //see note 1
}
}
}
}
어느, 귀하의 예제, 출력에서 : size
0에 설정
- :
{
...
"aggregations": {
"by_departments": {
"buckets": [
{
"key": "management", //see note 2
"doc_count": 2
},
{
"key": "accounts",
"doc_count": 1
},
{
"key": "it",
"doc_count": 1
}
]
}
}
}
두 개의 추가 노트 최대 버킷 수를 Integer.MAX_VALUE로 설정합니다. 너무 많은 수의 departments
값이있는 경우에는 사용하지 마십시오.
- 키는
terms
이고 결과는 departments
입니다. not_analyzed
으로 매핑 된 필드에 terms
집합을 사용해야합니다. 정확한 매핑을 {
...
"aggregations": {
"by_departments": {
"buckets": [
{
"key": "it",
"doc_count": 2
},
{
"key": "management",
"doc_count": 2
},
{
"key": "accounts",
"doc_count": 1
},
{
"key": "human",
"doc_count": 1
},
{
"key": "resource",
"doc_count": 1
}
]
}
}
}
:
{
"name": "Bill Gates",
"departments": [
{
"name": "IT"
},
{
"name": "Human Resource"
}
]
}
는 이런 종류의 결과가 발생합니다 :
예를 들어, 우리의 기본 매핑이 직원을 추가, (departments.name
는 analyzed
문자열입니다) :
POST company
{
"mappings": {
"employee": {
"properties": {
"name": {
"type": "string"
},
"departments": {
"type": "object",
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
Th 동일한 요청이 출력을 종료합니다.
{
...
"aggregations": {
"by_departments": {
"buckets": [
{
"key": "IT",
"doc_count": 2
},
{
"key": "Management",
"doc_count": 2
},
{
"key": "Accounts",
"doc_count": 1
},
{
"key": "Human Resource",
"doc_count": 1
}
]
}
}
}
희망이 있습니다.
완벽한 답변! 고마워요. – Tim