如何使用angular 5为elasticsearch编写请求体

How to write a request body for elastic search using angular5

我收到了从 Angular 触发 REST API 的要求。这个rest API 基本接受POST 方法和request body 中的elastic search

下面的片段我需要在从 Angular 代码进行休息 API 调用时传递请求正文。

{ "from": 0, "size": 200,
    "query": {
    "bool": { "must": [
    {"match": { "status": "A"}},
    {"match": { "type": "ITEM"}},
    {"terms": {"employee.department": [401,306]}}]
}}}

任何人都可以帮助我如何从 angular 代码进行此调用吗?

我已经用 Http 模块试过了,它的工作。

  const requestBody = { "from": 0, "size": 200,
                          "query": {
                            "bool": { "must": [
                          {"match": { "status": "A"}},
                          {"match": { "type": "dept"}},
                          {"terms": {"employee.department": [id1, id2]}}]
}}};

   var headers = new Headers();
   headers.append('Content-Type', 'application/json');
   headers.append('Accept', 'application/json');
   headers.append('Authorization', 'Basic <token>');

   const url = 'https://<rest-api>.com/<service>/v1/departments/@search' + '?apikey=' + '<<apikey>>';
   return this.httpHelperService.post(url, requestBody, {headers: headers});

   post(url: string, data: any, args?: RequestOptionsArgs): Observable<any> {
    if (args == null) {
      args = {};
    }
    if (args.headers === undefined) {
      this.getHeaders();
      args.headers = this.headers;
    }
    return this._http.post(url, JSON.stringify(data), args)
      .map((res: Response) => HttpHelperService.json(res))
      .catch(this.handleError);
  }