0

I am trying to make elasticSearch Post call within Angular 7 but it is throwing 400 bad error.

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`);
}

I am able to make successful call though when not passing any params and making regular get call

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

1 Answer 1

0

The JSON Query you are sending is meant to be sent in the body of the HTTP request. You are sending it through the URL

You have two options:

  1. Use the URI Search DSL found here. This has a more limited set of query options, but it does not require a request body
  2. Modify your Angular code to send the JSON in the actual body of the request. According to this post, HttpClient library does not have an easy way to do this for GET requests. You may have to write custom code for this.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.