Gale Yao
Gale Yao

Reputation: 163

How to execute a search template within Elasticsearch by using apache.httpcomponents.httpclient

curl -XGET http://localhost:9200/contact/_search/template?pretty -d '{"id":"contact", "params": {"q": "123456", "company": "2"}}'

It works well, but how can I use httpclient to make this call?

Upvotes: 0

Views: 75

Answers (1)

Val
Val

Reputation: 217424

You can easily achieve it like this:

StringRequestEntity entity = new StringRequestEntity(
    "{\"id\":\"contact\", \"params\": {\"q\": \"123456\", \"company\": \"2\"}}",
    "application/json",
    "UTF-8");

PostMethod post = new PostMethod("http://localhost:9200/contact/_search/template");
postMethod.addParameter("pretty", "");
postMethod.setRequestEntity(entity);
int statusCode = httpClient.executeMethod(post);

Upvotes: 1

Related Questions