# Any way to write the results of scripted bucket aggregations to a new index within elasticsearch itself?

**URL:** <https://discuss.elastic.co/t/any-way-to-write-the-results-of-scripted-bucket-aggregations-to-a-new-index-within-elasticsearch-itself/79806>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 7:56pm UTC](https://discuss.elastic.co/t/any-way-to-write-the-results-of-scripted-bucket-aggregations-to-a-new-index-within-elasticsearch-itself/79806 "2017-03-23T19:56:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casieowen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casieowen/32/8734_2.png) [@casieowen](https://discuss.elastic.co/u/casieowen)\
**Post date:** [March 23, 2017, 7:56pm UTC](https://discuss.elastic.co/t/any-way-to-write-the-results-of-scripted-bucket-aggregations-to-a-new-index-within-elasticsearch-itself/79806/1 "2017-03-23T19:56:42Z")

</div>

Hi,

Is there any way to do scripted bucket aggregations against existing indexes and write the results to a new index within elasticsearch itself? Like some way to combine the scripted bucket aggregations with the reindex API?

Thanks,  
Casie

---

<div class="post-metadata">

**Author:** ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)\
**Post date:** [March 23, 2017, 9:53pm UTC](https://discuss.elastic.co/t/any-way-to-write-the-results-of-scripted-bucket-aggregations-to-a-new-index-within-elasticsearch-itself/79806/2 "2017-03-23T21:53:30Z")

</div>

There's no way to do this using Elasticsearch alone. You can use X-Pack's `search` input ([https://www.elastic.co/guide/en/x-pack/current/input-search.html](https://www.elastic.co/guide/en/x-pack/current/input-search.html)) to define a query and then an `index` action ([https://www.elastic.co/guide/en/x-pack/current/actions-index.html](https://www.elastic.co/guide/en/x-pack/current/actions-index.html)) to insert the result back into an index.

---

<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:** [April 20, 2017, 9:53pm UTC](https://discuss.elastic.co/t/any-way-to-write-the-results-of-scripted-bucket-aggregations-to-a-new-index-within-elasticsearch-itself/79806/3 "2017-04-20T21:53:46Z")

</div>

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