# Query for documents by id, where id list is retrieved in another query

**URL:** <https://discuss.elastic.co/t/query-for-documents-by-id-where-id-list-is-retrieved-in-another-query/178509>\
**Category:** Elasticsearch\
**Created:** [April 25, 2019, 4:40pm UTC](https://discuss.elastic.co/t/query-for-documents-by-id-where-id-list-is-retrieved-in-another-query/178509 "2019-04-25T16:40:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newmz](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@Newmz](https://discuss.elastic.co/u/Newmz)\
**Post date:** [April 25, 2019, 4:40pm UTC](https://discuss.elastic.co/t/query-for-documents-by-id-where-id-list-is-retrieved-in-another-query/178509/1 "2019-04-25T16:40:30Z")

</div>

Hi folks, question.

short version:  
I have two indices. Both contain a matching `run_id` field, and also contain their own separate fields. I would like to get a list of `run_id` values from index A by querying for certain values in one of its fields, and then get a list of documents from index B with `run_id` values that match the list returned from the first query. How would I go about this?

long version:  
I need to visualize some test runs in kibana. I initially had some nested fields (one test run could have a variable amount of devices involved), but kibana does not support visualizing this. I decided to separate the devices into their own index and keep track of the test run they were involved in by a common `run_id` field. I need to visualize test data by a device attribute, so I figured I would query for ids from the device index, and use those ids in the test run index. How would I write this query? also: is this the right approach, or am I missing a key detail?

Thanks!

---

<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:** [May 23, 2019, 4:49pm UTC](https://discuss.elastic.co/t/query-for-documents-by-id-where-id-list-is-retrieved-in-another-query/178509/2 "2019-05-23T16:49:15Z")

</div>

Closed on May 23, 2019, 4:49pm UTC

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