简体   繁体   中英

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"}}'

它工作正常,但是如何使用httpclient进行此调用?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM