-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds link to good beginners guide to ES: http://seanmcgary.com/posts/…
- Loading branch information
Showing
2 changed files
with
29 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
var querystring = require('querystring'); // to build our post string | ||
var http = require('http'); | ||
|
||
function insert(id,tweet) { | ||
// Build the post string from an object | ||
var post_data = querystring.stringify({ | ||
"tweet" : tweet, | ||
"text" :"my amazing tweet text" | ||
}); | ||
var data = JSON.stringify({ | ||
"text" :"everything is awesome" | ||
}); | ||
|
||
// An object of options to indicate where to post to | ||
var post_options = { | ||
host: 'localhost', | ||
port: '9200', | ||
path: '/twitter/tweets/'+id+'/', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': post_data.length | ||
} | ||
}; | ||
console.log(' - - - - '); | ||
console.log(post_options); | ||
console.log(' - - - - '); | ||
console.log(post_data); | ||
console.log(' - - - - '); | ||
// Set up the request | ||
var post_req = http.request(post_options, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
console.log('Response: ' + chunk); | ||
}); | ||
}); | ||
// An object of options to indicate where to post to | ||
var post_options = { | ||
host: 'localhost', | ||
port: '9200', | ||
path: '/twitter/tweets/1234', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': Buffer.byteLength(data) | ||
} | ||
}; | ||
|
||
// post the data | ||
post_req.write(post_data); | ||
post_req.end(); | ||
// Set up the request | ||
var post_req = http.request(post_options, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
console.log('Response: ' + chunk); | ||
}); | ||
}); | ||
|
||
} | ||
console.log(data); | ||
console.log(' - - - - '); | ||
console.log(post_options); | ||
|
||
insert('1234', 'hello world'); | ||
// post the data | ||
post_req.write( data ); | ||
post_req.end(); |