# How can I retrieve the detailed doc matching the aggregation rule?

**URL:** <https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382>\
**Category:** Elasticsearch\
**Created:** [January 22, 2017, 7:08am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382 "2017-01-22T07:08:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)\
**Post date:** [January 22, 2017, 7:08am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382/1 "2017-01-22T07:08:06Z")

</div>

Well, I have a index for the detailed docs, the fields are like this: the house's geo\_point, the house's name.  
With a geohash\_grid aggregation, I can retrieve those geohash\_grids and how many houses within it.

However, I want to see the exact house's information(the detailed ones) for the geohash\_grid buckets which contain less than 3 houses.

in SQL-like format, that query will be like this:  
SELECT \*  
FROM detailed\_table t  
WHERE geohash\_grid in  
(  
SELECT geohash\_grid, COUNT(_)  
FROM detailed\_table t  
GROUP BY geohash\_grid  
HAVING COUNT(_) \< 3  
);

thanks:)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 22, 2017, 8:26am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382/2 "2017-01-22T08:26:20Z")

</div>

Top hits: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)

---

<div class="post-metadata">

**Author:** ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)\
**Post date:** [January 22, 2017, 8:44am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382/3 "2017-01-22T08:44:59Z")

</div>

great! that's what I want 😛

---

<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:** [February 19, 2017, 8:45am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-detailed-doc-matching-the-aggregation-rule/72382/4 "2017-02-19T08:45:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
