# Indexing from a query with script

**URL:** <https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437>\
**Category:** Elasticsearch\
**Created:** [July 3, 2018, 6:22pm UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437 "2018-07-03T18:22:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![juanaramis](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@juanaramis](https://discuss.elastic.co/u/juanaramis)\
**Post date:** [July 3, 2018, 6:22pm UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437/1 "2018-07-03T18:22:21Z")

</div>

Hi there,

Is there a way to populate an index with the results of a query? I guess yes, but can I apply a script before putting the data in the destination index?

Thanks in advance

J.

---

<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:** [July 3, 2018, 6:33pm UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437/2 "2018-07-03T18:33:19Z")

</div>

The reindex API does that basically.

---

<div class="post-metadata">

**Author:** ![juanaramis](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@juanaramis](https://discuss.elastic.co/u/juanaramis)\
**Post date:** [July 3, 2018, 10:57pm UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437/3 "2018-07-03T22:57:35Z")

</div>

Thanks for the fast answer.  
Just a question, how do I refer to the fields in the source and these in the destination?

Thanks in advance

J.

---

<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:** [July 4, 2018, 5:11am UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437/4 "2018-07-04T05:11:20Z")

</div>

reindex API reads the whole `_source` and reindex it entirely.  
If you need to modify the `_source` field, then use an ingest pipeline.

---

<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:** [August 1, 2018, 5:11am UTC](https://discuss.elastic.co/t/indexing-from-a-query-with-script/138437/5 "2018-08-01T05:11:25Z")

</div>

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