Created
April 25, 2014 21:10
-
-
Save jprante/11303384 to your computer and use it in GitHub Desktop.
Demo script for node.js to connect to elasticsearch-transport-websocket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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