簡體   English   中英

Elasticsearch curl請求無法在Angular 4中按預期工作

[英]Elasticsearch curl request not working as expected in Angular 4

我在Angular項目中安裝了curl npm軟件包( https://www.npmjs.com/package/curl ),並且我一直在使用curl.postJSON()方法發布到雲上的Elasticsearch集群中。 我現在需要使用curl.get()方法,它無法按預期工作。

在終端中,這是有效的curl請求,我需要在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:未定義”

由於console.log(err,body),它還返回了我的Elasticsearch集群中的每個文檔(共33個)。 同時,當我在終端中運行curl命令時,它僅返回3個文檔。 有什么想法可以使我獲得正確的卷曲請求嗎?

我認為這可能與終端curl請求中的“ -d”有關,而不與角度有關,因為當我在終端中運行不帶“ -d”的get請求時,它將返回elasticsearch集群中的所有文檔。 我仍然不知道如何將curl -get()與“ -d”合並。

  1. curl軟件包自2011年以來沒有變化。我推薦使用官方的elasticsearch.js客戶端( https://www.elastic.co/guide/zh-CN/elasticsearch/client/javascript-api/current/index.html )。

  2. 您可以從技術上發送帶有主體的HTTP GET請求,但是由於各種原因,這樣做有缺點( GET HTTP請求有效負載

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM