# How to indexing realtime data in to Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662>\
**Category:** Elasticsearch\
**Created:** [April 12, 2019, 3:33pm UTC](https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662 "2019-04-12T15:33:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed\_eshaftri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohamed_eshaftri/32/43987_2.png) [@Mohamed\_eshaftri](https://discuss.elastic.co/u/Mohamed_eshaftri)\
**Post date:** [April 12, 2019, 3:33pm UTC](https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662/1 "2019-04-12T15:33:29Z")

</div>

hello,  
i am new Elasticsearch user, i would like to know how i can indexing realtime data from webSocket API and index this data, using Javascript.

even some link page to start, that will be helpful.

thank you.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 12, 2019, 5:42pm UTC](https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662/2 "2019-04-12T17:42:52Z")

</div>

you would need a component that receives data on a websocket and creates elasticsearch bulk requests (that are sent via HTTP) out of that stream of data. Elasticsearch itself cannot communicate via websockets, just regular HTTP.

Logstash features a [websocket input](https://www.elastic.co/guide/en/logstash/7.0/plugins-inputs-websocket.html) that might fit your needs.

---

<div class="post-metadata">

**Author:** ![Mohamed\_eshaftri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohamed_eshaftri/32/43987_2.png) [@Mohamed\_eshaftri](https://discuss.elastic.co/u/Mohamed_eshaftri)\
**Post date:** [April 13, 2019, 7:49pm UTC](https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662/3 "2019-04-13T19:49:29Z")

</div>

Thanks Alexander,

i managed to work with websocket input, and run it in my machine. now i want to consume data from [https://www.blockchain.com/api/api\_websocket](https://www.blockchain.com/api/api_websocket), which requires subscribe to channel . in order to insert the message data into an Elasticsearch container using Javascript.

when i use Javascript to consume the data, it work perfec my code below.

```
    <script>
            var ws = new WebSocket(" wss://ws.blockchain.info/inv");
            ws.onopen = function(){
                ws.send(JSON.stringify({"op":"unconfirmed_sub"}))
                console.log('mash')
            };
            ws.onmessage = function(msg){
                var response = JSON.parse(msg.data);
                console.log('response')
            }
        </script> 

```

However, when i implement in Websocket input plugin, and below my Websocket input plugin config code.

```
input {
    websocket {
      mode => "client"
      url => "wss://ws.blockchain.info/inv"
      type => "string"
    }
  }

  output {
    elasticsearch {
      hosts => ["localhost:9200"]
      index => "calidog"
    }
    stdout { codec => rubydebug }
  }

```

when i run the config file, does't show anything.

```
[2019-04-13T18:15:16,387][INFO][logstash.agent] Successfully started Logstash API endpoint {:port=>9600}
[2019-04-13T18:15:21,190][INFO][logstash.runner] Logstash shut down.

```

Thank you .

---

<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:** [May 11, 2019, 7:49pm UTC](https://discuss.elastic.co/t/how-to-indexing-realtime-data-in-to-elasticsearch/176662/4 "2019-05-11T19:49:33Z")

</div>

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