# Query two indexes and store output into new index

**URL:** <https://discuss.elastic.co/t/query-two-indexes-and-store-output-into-new-index/87566>\
**Category:** Elasticsearch\
**Created:** [May 30, 2017, 12:35pm UTC](https://discuss.elastic.co/t/query-two-indexes-and-store-output-into-new-index/87566 "2017-05-30T12:35:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurveer\_Singh](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@Gurveer\_Singh](https://discuss.elastic.co/u/Gurveer_Singh)\
**Post date:** [May 30, 2017, 12:35pm UTC](https://discuss.elastic.co/t/query-two-indexes-and-store-output-into-new-index/87566/1 "2017-05-30T12:35:13Z")

</div>

Hi,

I have two indexes with different data but both indexes has mutual filed Roll Number. Following is example:

student\_index has following data  
Roll Number: 123456  
Name: Bob  
Last Name: Michel  
Class: 8th

finance\_index has following data  
Roll Number: 123456  
Fee: 8000

I want to query both index based on roll no and expected output is:  
Roll Number: 123456  
Name: Bob  
Last Name: Michel  
Class: 8th  
Fee: 8000

and want to store output in 3rd index final\_student\_index.

I have approximately 23000 records, how I can achieve this and what is best way to do such task.

---

<div class="post-metadata">

**Author:** ![Tetrapack](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Tetrapack](https://discuss.elastic.co/u/Tetrapack)\
**Post date:** [May 31, 2017, 1:03pm UTC](https://discuss.elastic.co/t/query-two-indexes-and-store-output-into-new-index/87566/2 "2017-05-31T13:03:37Z")

</div>

Hello,

an algo like that could do the job:

Retrieve through a scroll request the whole index student\_index  
Retrieve through a scroll request the whole index finance\_index  
make consolidated objects using a loop on student\_index data  
bulk that new list into a new index.

23000 documents x 3 is easy to process in memory by a program in c# or java..

if there are too many documents, the algo could be like that :

begin to scroll the student\_index.  
At each scroll, make a multiget or search into finance\_data on Roll Number retrieved.  
Consolidate  
Bulk  
Next scroll...

Anyway, it would be interesting to directly build one consolidated index... like indexing a 'final\_student\_index' the equivalent of student\_index, and, instead of mounting the finance\_index, do an update of 'final\_student\_index' to add the "Fee" field.

---

<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:** [June 28, 2017, 1:04pm UTC](https://discuss.elastic.co/t/query-two-indexes-and-store-output-into-new-index/87566/3 "2017-06-28T13:04:23Z")

</div>

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