Skip to content

Instantly share code, notes, and snippets.

@jprante
Created April 25, 2014 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jprante/11303384 to your computer and use it in GitHub Desktop.
Save jprante/11303384 to your computer and use it in GitHub Desktop.
Demo script for node.js to connect to elasticsearch-transport-websocket
/*
npm install ws
node demo-websocket-client.js
( ---> curl 'localhost:9200/myindex/_search')
Ctrl-C
*/
var WebSocket = require('ws')
,socket = new WebSocket("ws://localhost:9400/websocket");
socket.onopen = function() {
socket.send(JSON.stringify({
"type" : "index",
"data" : {
"index" : "myindex",
"type" : "mytype",
"id" : "myid",
"data" : {
"field1" : "value1",
"field2" : "value2"
}
}
}));
socket.send(JSON.stringify({
"type" : "flush"
}));
};
socket.onmessage = function(message) {
console.log(message);
};
socket.onclose = function() {
console.log("closed");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment