Skip to content

Instantly share code, notes, and snippets.

@phpnode
Created June 22, 2011 19:42
Show Gist options
  • Save phpnode/1040963 to your computer and use it in GitHub Desktop.
Save phpnode/1040963 to your computer and use it in GitHub Desktop.
var http = require('http'), urlParser = require('url');
http.createServer(function(req, res) {
var query, q, elastic, data = '', agent;
console.log("Connected: " +req.connection.remoteAddress);
q = urlParser.parse(req.url, true).query.q;
if (q === undefined) {
console.log("WTF");
return;
}
query = {
fields: ['name', 'title', 'description', 'url', 'domain'],
query: {
flt: {
fields: ['name', 'title', 'description', 'url', 'domain', 'plainText'],
like_text: q
}
}
};
agent = http.getAgent("localhost", 9200);
agent.maxSockets = 100;
elastic = http.request({
agent: agent,
host: 'localhost',
port: 9200,
path: '/main/Webapp/_search',
method: 'POST'
}, function(response) {
response.on('data', function (chunk) {
data += chunk;
}).on('end', function () {
res.end(data);
});
});
elastic.write(JSON.stringify(query));
elastic.end();
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment