-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchDocument.js
59 lines (55 loc) · 1.53 KB
/
searchDocument.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
52
53
54
55
56
57
58
59
var Q = require('q');
var config = require('./config');
// var elastic_client = config.elastic_client;
var elasticsearch_client_aws = config.elasticsearch_client_aws;
function search_document(obj_index, obj_type, match_string){
console.log("inside the search_document");
// initialize the Q object for making the promise
var defered = Q.defer();
// make the query object first
var query_obj = {
"query":{
"match": match_string
}
};
elasticsearch_client_aws.search({
index: obj_index,
type: obj_type,
body: {
from:0,
size:200,
query: {
match: {
message: match_string
}
}
}
}).then(function (resp) {
// console.log("after getting the result");
var hits = resp.hits.hits;
defered.resolve(hits);
}, function (err) {
console.trace(err.message);
});
// //the query for searching the elastic search with query string to be match_string for local elasticseach.
// elastic_client.search({
// index: obj_index,
// type: obj_type,
// body: {
// query: {
// match: {
// message: match_string
// }
// }
// }
// }).then(function (resp) {
// // console.log("after getting the result");
// var hits = resp.hits.hits;
// defered.resolve(hits);
// }, function (err) {
// console.trace(err.message);
// });
// returning the promise that value will be retured.
return defered.promise;
}
module.exports.search_document = search_document;