简体   繁体   English

如何通过使用apache.httpcomponents.httpclient在Elasticsearch中执行搜索模板

[英]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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Apache HttpComponents HttpClient设置'Referer'HTTP头 - How to set 'Referer' HTTP header using Apache HttpComponents HttpClient Apache HttpComponents HttpClient超时 - Apache HttpComponents HttpClient timeout java HttpClient.execute(get)中的Apache HttpComponents什么都不做 - Apache HttpComponents in java HttpClient.execute(get) not doing anything 如何使用 Apache httpcomponents 从 NHttpRequestHandler 中告诉远程 IP 地址? - How do I tell the remote IP address from within NHttpRequestHandler using Apache httpcomponents? 使用 Apache HttpComponents HttpClient 测量带宽使用情况 - Measure bandwidth usage with Apache HttpComponents HttpClient 警告:使用jfrog和android-maven-plugin时,将忽略org.apache.httpcomponents:httpclient:4.2.1依赖项 - Warning:Dependency org.apache.httpcomponents:httpclient:4.2.1 is ignored when using jfrog and android-maven-plugin 使用Apache HttpComponents发送xml - Sending xml using Apache HttpComponents 如何使用Apache HttpComponents从Java套接字获取HTTPRequest - How to get an HTTPRequest from a Java Socket using Apache HttpComponents 如何使用 Gradle 导入 o​​rg.apache.httpcomponents - How to import org.apache.httpcomponents using Gradle 警告:依赖org.apache.httpcomponents:httpclient:4.0.1被忽略 - Warning:Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM