# It's possible read data from Elasticsearch to postgres inside a pgsql function? How?

**URL:** <https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513>\
**Category:** Elasticsearch\
**Created:** [June 22, 2017, 6:24pm UTC](https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513 "2017-06-22T18:24:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parentemj](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@parentemj](https://discuss.elastic.co/u/parentemj)\
**Post date:** [June 22, 2017, 6:24pm UTC](https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513/1 "2017-06-22T18:24:53Z")

</div>

HI

it's possible read data from elasticsearch "inside" a pgsql function (i need read some data and write them in a DB Table (postgres)).

all the information i finded is about write data from postgres DB to ElasticSearch. But I need the opposite. It's possible in a DB pgsql function? How???

We have the index inside the elastic. So, I only need to connect me with the elastic inside the pgsql function.

thanks

mj

---

<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:** [June 22, 2017, 10:27pm UTC](https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513/2 "2017-06-22T22:27:56Z")

</div>

May be you can extract the data from elasticsearch using logstash and the [elasticsearch input](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html).

But AFAIK, there is no jdbc output available. (Might be something useful to ask though).

For now, you can export to CSV with the [output-csv filter](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-csv.html). Then use whatever import tool you have to insert into Postgresql.

HTH

---

<div class="post-metadata">

**Author:** ![parentemj](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@parentemj](https://discuss.elastic.co/u/parentemj)\
**Post date:** [June 23, 2017, 9:04am UTC](https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513/3 "2017-06-23T09:04:58Z")

</div>

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:** [July 21, 2017, 9:05am UTC](https://discuss.elastic.co/t/its-possible-read-data-from-elasticsearch-to-postgres-inside-a-pgsql-function-how/90513/4 "2017-07-21T09:05:12Z")

</div>

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