-
-
Save jp/8d6619d5e67b51694236 to your computer and use it in GitHub Desktop.
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