我在我的Angular项目中安装了curl npm包(https://www.npmjs.com/package/curl),并且我一直使用curl.postJSON()方法在云上发布到我的Elasticsearch集群。我现在需要使用curl.get()方法,它不能按预期工作。
在终端中,这是有效的卷曲请求,我需要在我的Angular项目中使用:
curl -XGET https://search-example-xxxxxxxxxxxxxxxxxxx.us-east-2.es.amazonaws.com/myproject/_search? -d '
{
"query" :
{ "match": { "myfield": "NJ-PA-xxxx-x" } }
}
'
这是我的主要组件中无法正常工作的方法:
myMethod(){
var getData = { "query" : { "match": { "myfield": "NJ-PA-xxxx-x" } } };
var circLink = curl.get("https://search-example-xxxxxxxxxxxxxxxxxxx.us-east-2.es.amazonaws.com/myproject/_search", getData,
function (err, httpResponse, body) {
console.log(err, body);
});
console.log('this is the circLink: ' + circLink );
}
返回“这是circLink:undefined”
因为console.log(错误,正文),它还返回我的elasticsearch集群中的每个文档(全部33个)。同时,当我在终端中运行curl命令时,它只返回3个文档。我有什么想法可以获得正确的卷曲请求吗?
我认为这可能与我的终端curl请求中的“-d”有关,而不是角度,因为当我在终端中运行没有“-d”的get请求时,它会返回所有文档中的弹性搜索集群。我仍然不知道如何将“-d”与curl.get()结合使用
答案 0 :(得分:0)
自2011年以来,curl包没有变化。我推荐官方的elasticsearch.js客户端(https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html)。
您可以从技术上发送带有正文的HTTP GET请求,但由于各种原因(GET HTTP request payload)