【问题标题】:ElasticSearch Post call within Angular7 is throwing 400 bad errorAngular7 中的 ElasticSearch Post 调用抛出 400 错误
【发布时间】:2019-12-05 14:20:23
【问题描述】:

我正在尝试在 Angular 7 中进行 elasticSearch Post 调用,但它会引发 400 错误。

public elasticSearch<T>(): Observable<ElasticModel<T>> {
  const reqBody = {
    "query": {
      "bool": {
        "should": {
          "match": {
            "status": "IN_PROGRESS"
          }
        }
      }
    }
  };
  // tslint:disable-next-line:max-line-length
  return this.http.get<ElasticResponseData<T>>(`${this.apiUri}/_search/query?indexName=` + 1 + `&query=` + JSON.stringify(reqBody) + `&size=` + 2 + `&from=` + (page - 1) * size);
  // return this.http.get<ElasticResponseData<T>>(`${this.apiUri}/_search`);
}

虽然没有传递任何参数并进行常规get call,但我能够成功调用

return this.http.get<ElasticResponseData<T>>(`${this.apiUri}/_search`);

【问题讨论】:

    标签: angular elasticsearch datatable angular-material angular-datatables


    【解决方案1】:

    您发送的 JSON 查询应在 HTTP 请求的 正文 中发送。您通过 URL

    发送它

    你有两个选择:

    1. 使用 URI 搜索 DSL found here。这有一组更有限的查询选项,但它不需要请求正文
    2. 修改您的 Angular 代码以在请求的实际正文中发送 JSON。根据this post,HttpClient 库没有简单的方法来处理 GET 请求。您可能需要为此编写自定义代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多