# How can I migrate from elasticsearch to postgresql?

**URL:** <https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041>\
**Category:** Elasticsearch\
**Created:** [September 1, 2021, 12:38pm UTC](https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041 "2021-09-01T12:38:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xemyleex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xemyleex/32/56623_2.png) [@xemyleex](https://discuss.elastic.co/u/xemyleex)\
**Post date:** [September 1, 2021, 12:38pm UTC](https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041/1 "2021-09-01T12:38:53Z")

</div>

I have to migrate from elasticsearch to postgresql.

What is the best way to do that?

I found this plugin: [Elasticsearch output plugin | Logstash Reference [7.14] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html)

Is it useful for my purpose?

Thanks 🙂

---

<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:** [September 7, 2021, 3:00pm UTC](https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041/2 "2021-09-07T15:00:15Z")

</div>

So you have your data in Elasticsearch and you want to store them in Postgresql, right?

Do you want to do both or just keep Postgresql?  
If the former, I'd recommend modifying the application layer if possible and send data to elasticsearch in the same "transaction" as you are sending your data to the database.

I shared most of my thoughts there: [Advanced Search for Your Legacy Application - -Xmx128gb -Xms128gb](http://david.pilato.fr/blog/2015/05/09/advanced-search-for-your-legacy-application/)

Have also a look at this ["live coding" recording](https://www.elastic.co/fr/blog/how-to-add-powerful-search-existing-sql-applications-elasticsearch-video-tutorial).

If you just want to move the data, you should IMHO write a script which does that.  
basically read all the data from Elasticsearch using the scroll API and transform the JSON documents to whatever datastructure you want and store in the database.

---

<div class="post-metadata">

**Author:** ![xemyleex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xemyleex/32/56623_2.png) [@xemyleex](https://discuss.elastic.co/u/xemyleex)\
**Post date:** [September 8, 2021, 2:15pm UTC](https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041/3 "2021-09-08T14:15:01Z")

</div>

I want to move the data. Ok so I need a script. 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:** [October 6, 2021, 2:15pm UTC](https://discuss.elastic.co/t/how-can-i-migrate-from-elasticsearch-to-postgresql/283041/4 "2021-10-06T14:15:43Z")

</div>

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