# Postgres streams to elastic streams

**URL:** <https://discuss.elastic.co/t/postgres-streams-to-elastic-streams/92798>\
**Category:** Elasticsearch\
**Created:** [July 12, 2017, 11:17am UTC](https://discuss.elastic.co/t/postgres-streams-to-elastic-streams/92798 "2017-07-12T11:17:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt\_baker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_baker/32/19998_2.png) [@matt\_baker](https://discuss.elastic.co/u/matt_baker)\
**Post date:** [July 12, 2017, 11:17am UTC](https://discuss.elastic.co/t/postgres-streams-to-elastic-streams/92798/1 "2017-07-12T11:17:43Z")

</div>

Hi,

Hi,  
i wanted to append below object to every object in stream

`{"index":{"_index":"tvseries","_type":"internindex"}}`  
my stream looks like this

```
[
  {"showname":"The X Files","episode":"04","content":"Before what?","season":"1"},
  {"showname":"The X Files","episode":"04","content":"Before what?","season":"1"},
{"showname":"The X Files","episode":"01","content":"What?","season":"1"}
]

```

what my stream should look like !

```
-> POST http://localhost:9200/_bulk
  {"index":{"_index":"tvseries","_type":"internindex"}}
  {"showname":"The X Files","episode":"04","content":"Before what?","season":"1"}
  {"index":{"_index":"tvseries","_type":"internindex"}}
  {"showname":"The X Files","episode":"04","content":"Great.","season":"1"}
  {"index":{"_index":"tvseries","_type":"internindex"}}
  {"showname":"The X Files","episode":"01","content":"What?","season":"1"}

```

how can i achieve this using jsonstream in my existing belowcodebase

```
    var stream = new ElasticsearchWritableStream(client, {
      highWaterMark: 256,
      flushTimeout: 500
    });
  
pg.connect(connectionString,function(err, client, done) {
  if(err) throw err;
  var query = new QueryStream('SELECT * FROM srt limit 2')
  var streams = client.query(query)
  
  //release the client when the stream is finished
  streams.on('end', done)
  streams.pipe(JSONStream.stringify()).pipe(stream)
}

```

any other npm package which converts pgstreams directly to elastic search streams with some basic input params !

the npm packages currently i am using

1. For bulk insertion in elasticsearch !  
[elasticsearch-writable-stream](https://github.com/voldern/elasticsearch-writable-stream)
2. for getting data from postgres into streams !  
[pg-query-stream](https://github.com/brianc/node-pg-query-stream)
3. missing piece is converting postgres streams into elastic writable streams !

any suggestion and recommendations on how to resolve this

---

<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 9, 2017, 11:17am UTC](https://discuss.elastic.co/t/postgres-streams-to-elastic-streams/92798/2 "2017-08-09T11:17:47Z")

</div>

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