-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Closed
Labels
Description
I have issue with aggregation result then i use nested aggregation in terms aggregation.
Tested with ES 1.4.[1,2].
Create mapping and add documents
DELETE test/product/_mapping
POST test/product/_mapping
{
"properties": {
"categories": {
"type": "long"
},
"name": {
"type": "string"
},
"property": {
"type": "nested",
"properties": {
"id": {
"type": "long"
}
}
}
}
}
POST test/product
{
"name":"product1",
"categories":[1,2,3,4],
"property":[
{"id":1},
{"id":2},
{"id":3}
]
}
POST test/product
{
"name":"product2",
"categories":[1,2],
"property":[
{"id":1},
{"id":5},
{"id":4}
]
}
Aggregation query
GET test/product/_search
{
"size": 0,
"aggs": {
"category": {
"terms": {"field": "categories","size": 0},
"aggs": {
"property": {
"nested": {"path": "property"},
"aggs": {
"property_id": {
"terms": {"field": "property.id","size": 0}
}
}
}
}
}
}
}
Result
...
"aggregations": {
"category": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1,
"doc_count": 2,
"property": {
"doc_count": 6,
"property_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1,
"doc_count": 2
},
{
"key": 2,
"doc_count": 1
},
{
"key": 3,
"doc_count": 1
},
{
"key": 4,
"doc_count": 1
},
{
"key": 5,
"doc_count": 1
}
]
}
}
},
{
"key": 2,
"doc_count": 2,
"property": {
"doc_count": 0,
"property_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
},
{
"key": 3,
"doc_count": 1,
"property": {
"doc_count": 0,
"property_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
},
{
"key": 4,
"doc_count": 1,
"property": {
"doc_count": 0,
"property_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
]
}
}
...
I have no sub aggregation result in aggregation "category" keys 2,3,4