Created
May 1, 2020 06:55
-
-
Save wangyu-/634fe1e5af74b6a3ab78fd04efef0598 to your computer and use it in GitHub Desktop.
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
exports.handler = (event) => { | |
var host="111"; | |
var path="/[email protected]/_search" | |
/*var query={ | |
"query": { | |
"match": { | |
"text": { | |
"query": "you get", | |
"operator": "and" | |
} | |
} | |
} | |
}*/ | |
var query={ | |
"query": { | |
"match_phrase": { | |
"text" : { | |
"query" : "can you get can", | |
"slop" : 0 | |
} | |
} | |
} | |
}; | |
handle_request(host,path, 'POST', query, function(data) { | |
console.log('Fetched ',JSON.stringify(data)); | |
}); | |
}; | |
var querystring = require('querystring'); | |
var https = require('https'); | |
function handle_request(host,endpoint, method, data, success) { | |
var dataString = JSON.stringify(data); | |
var headers = {}; | |
if (method == 'GET') { | |
endpoint += '?' + querystring.stringify(data); | |
console.log(endpoint); | |
} | |
else { | |
headers = { | |
'Content-Type': 'application/json', | |
'Content-Length': dataString.length | |
}; | |
} | |
var options = { | |
host: host, | |
path: endpoint, | |
method: method, | |
headers: headers | |
}; | |
var req = https.request(options, function(res) { | |
res.setEncoding('utf-8'); | |
var responseString = ''; | |
res.on('data', function(data) { | |
responseString += data; | |
}); | |
res.on('end', function() { | |
console.log(responseString); | |
var responseObject = JSON.parse(responseString); | |
success(responseObject); | |
}); | |
}); | |
req.write(dataString); | |
req.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment