# How to query again with query results?

**URL:** <https://discuss.elastic.co/t/how-to-query-again-with-query-results/64670>\
**Category:** Elasticsearch\
**Created:** [November 2, 2016, 6:15am UTC](https://discuss.elastic.co/t/how-to-query-again-with-query-results/64670 "2016-11-02T06:15:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjahn90](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@sjahn90](https://discuss.elastic.co/u/sjahn90)\
**Post date:** [November 2, 2016, 6:15am UTC](https://discuss.elastic.co/t/how-to-query-again-with-query-results/64670/1 "2016-11-02T06:15:02Z")

</div>

My data sample is like this. Key-value log

"Clientip”: “10.1.1.1” “downstreamid”:10 “upstreamid”: 1  
..  
..  
"Clientip”: “10.2.1.1” “downstreamid”:1 “upstreamid”: 22  
..  
..  
"Clientip”: “10.3.1.1” “downstreamid”:22 “upstreamid”: 44  
..  
..

From above sample, pseudo code are :

select clientip, downstreamid, upstreamid from index\_name where downstreamid=10  
Print clientip, downstreamid, upstreamid  
key = upstreamid

Select clientip, downstreamid, upstreamid from index\_name where downstream=key  
Print clientip, downstreamid, upstreamid  
key = upstreamid

Select clientip, downstreamid, upstreamid from index\_name where downstream=key  
Print clientip, downstreamid, upstreamid

I’d like to query again with result of previous query. Is it possible to query using one Elasticsearch DSL query ? If not possible, please recommend other idea.

Eventually, I want to use this query on Kibana.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 2, 2016, 9:34am UTC](https://discuss.elastic.co/t/how-to-query-again-with-query-results/64670/2 "2016-11-02T09:34:34Z")

</div>

You need your code to do this, it's nothing ES or KB can do for you.

---

<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:07pm UTC](https://discuss.elastic.co/t/how-to-query-again-with-query-results/64670/3 "2017-07-05T22:07:31Z")

</div>


