Created
May 1, 2020 06:55
-
-
Save wangyu-/634fe1e5af74b6a3ab78fd04efef0598 to your computer and use it in GitHub Desktop.
Revisions
-
wangyu- created this gist
May 1, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ exports.handler = (event) => { var host="111"; var path="/wy2@1.com/_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(); }