# Can I search a query based on a results from aggregations?

**URL:** <https://discuss.elastic.co/t/can-i-search-a-query-based-on-a-results-from-aggregations/23263>\
**Category:** Elasticsearch\
**Created:** [April 15, 2015, 9:04pm UTC](https://discuss.elastic.co/t/can-i-search-a-query-based-on-a-results-from-aggregations/23263 "2015-04-15T21:04:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Xiong](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Lincoln\_Xiong](https://discuss.elastic.co/u/Lincoln_Xiong)\
**Post date:** [April 15, 2015, 9:04pm UTC](https://discuss.elastic.co/t/can-i-search-a-query-based-on-a-results-from-aggregations/23263/1 "2015-04-15T21:04:05Z")

</div>

Hi good people,

I am using elasticsearch for some logs monitoring and analysis. Sometimes I  
need to use aggregation to return distinct values of a field to research  
into some issue. I was always wondering if I can run a query based on the  
results from aggregation. For now, I used python api to achieve what I  
want, by store the results of aggregation in a list and make a new query  
search based on the value in the list.

And I was hinted by someone said I can do some research with nested type or  
parent/child type. But seems all my data is parsing from plaintext and  
structured by grok in Logstash, I don't think I am able to build nested  
type.

So you can image that some documents in my case will have the same value  
for a specific field. If there is a way to put these documents with the  
same value in a field together (even if I really need to reindex) I will  
try to implement it and test the performance. But is that possible in es?

Cheers,

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/23aed5b8-c908-422a-9701-c198f31cb65e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/23aed5b8-c908-422a-9701-c198f31cb65e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:19am UTC](https://discuss.elastic.co/t/can-i-search-a-query-based-on-a-results-from-aggregations/23263/2 "2017-07-06T00:19:29Z")

</div>


