-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (40 loc) · 1020 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var express = require('express'),
ElasticSearchClient = require('elasticsearchclient');
var serverOptions = {
host: process.env.ES_PORT_9200_TCP_ADDR || 'localhost',
port: process.env.ES_PORT_9200_TCP_PORT || 9200
};
var es = new ElasticSearchClient(serverOptions);
var app = express();
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.get('/', function (req, res) {
res.render('index');
});
app.get('/search', function(req, res){
var qryObj = {
"query": {
"filtered": {
"query": {
"query_string": {
"query": req.query.q
}
},
"filter": {
"query": {
"match": {
"link": 'youtube'
}
}
}
}
}
};
es.search('links', 'link', qryObj, function(err, data){
var resp = JSON.parse(data);
res.json({hits: resp.hits.hits});
});
});
app.use(express.static(__dirname + '/public'))
app.listen(3000);
console.log('Listening on 3000');