# \[Java\] Mutil-field terms aggregation fetch the result

**URL:** <https://discuss.elastic.co/t/java-mutil-field-terms-aggregation-fetch-the-result/48789>\
**Category:** Elasticsearch\
**Created:** [April 29, 2016, 9:11am UTC](https://discuss.elastic.co/t/java-mutil-field-terms-aggregation-fetch-the-result/48789 "2016-04-29T09:11:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xuan\_Yi](https://avatars.discourse-cdn.com/v4/letter/x/8797f3/32.png) [@Xuan\_Yi](https://discuss.elastic.co/u/Xuan_Yi)\
**Post date:** [April 29, 2016, 9:11am UTC](https://discuss.elastic.co/t/java-mutil-field-terms-aggregation-fetch-the-result/48789/1 "2016-04-29T09:11:21Z")

</div>

Elasticsearch 2.3.0  
I want to get the result aggregations use Java. My expected Json result is [{"by\_from:{"nearme":xxx,"xiaomi":xxx,"huaweisf":xxx,"qq":xxx}"},{"by\_sdkver":{"3.1.4":xxx,"3.0.6":xxx,"3.1.1":xxx}}]. When I use the signal field(by\_from) terms aggregation , that is success. But when I use the mutil-field ,like by\_from and by\_sdkver, the result is so amazing, that is ,{"by\_from":{"3.1.4":xxx,"3.0.6":xxx,"3.1.1":xxx}},{"by\_sdkver":{"3.1.4":xxx,"3.0.6":xxx,"3.1.1":xxx}} , "by\_sdk" and "by\_from" have the same content !  
The trouble is that I wanna to get the detail "by\_from" keys,like "nearme","xiaomi".. I don't know why the result is that. If I want get the expected result ,how should I do?  
Mutil-field terms aggregation result:  
{  
"aggregations" : {  
"by\_from" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 175,  
"buckets" : [ {  
"key" : "nearme",  
"doc\_count" : 514,  
"by\_sdkver" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "3.1.4",  
"doc\_count" : 492  
}, {  
"key" : "3.0.6",  
"doc\_count" : 20  
}, {  
"key" : "3.1.1",  
"doc\_count" : 2  
} ]  
}  
}, {  
"key" : "xiaomi",  
"doc\_count" : 426,  
"by\_sdkver" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "3.1.4",  
"doc\_count" : 410  
}, {  
"key" : "3.1.1",  
"doc\_count" : 11  
}, {  
"key" : "3.0.6",  
"doc\_count" : 5  
} ]  
}  
}, {  
"key" : "huaweisf",  
"doc\_count" : 202,  
"by\_sdkver" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "3.1.4",  
"doc\_count" : 202  
} ]  
}  
}, {  
"key" : "qq",  
"doc\_count" : 167,  
"by\_sdkver" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "3.1.4",  
"doc\_count" : 130  
}, {  
"key" : "3.0.6",  
"doc\_count" : 35  
}, {  
"key" : "3.1.1",  
"doc\_count" : 2  
} ]  
}  
}]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:55pm UTC](https://discuss.elastic.co/t/java-mutil-field-terms-aggregation-fetch-the-result/48789/2 "2017-07-05T22:55:17Z")

</div>

Closed on July 5, 2017, 10:55pm UTC


