http4client rest buik elasticsearch
来源:互联网 发布:coc女王升级数据2017 编辑:程序博客网 时间:2024/05/23 17:32
maven
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.4</version></dependency>
bulk
/** * { "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } } * @return */ private static String buildDelete(JSONObject json,String index,String type,String id){ StringBuffer sb = new StringBuffer(); String str="{ \"delete\" : { \"_index\" : \""+index+"\", \"_type\" : \""+type+"\", \"_id\" : \""+id+"\" } }"; sb.append(str).append("\n"); System.out.println("delete "+sb.toString()); return sb.toString(); } /** * { "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} } * { "doc" : {"field2" : "value2"} } * @return */ private static String buildUpdate(JSONObject json,String index,String type,String id){ StringBuffer sb = new StringBuffer(); String str="{ \"update\" : { \"_index\" : \""+index+"\", \"_type\" : \""+type+"\", \"_id\" : \""+id+"\" } }"; sb.append(str).append("\n"); sb.append("{ \"doc\" : ").append(json).append("}").append("\n"); System.out.println("update: "+ sb.toString());return sb.toString(); } private static String buildInsert(JSONObject json,String index,String type,String id){ StringBuffer sb = new StringBuffer(); String str="{ \"index\" : { \"_index\" : \""+index+"\", \"_type\" : \""+type+"\", \"_id\" : \""+id+"\" } }"; sb.append(str).append("\n"); sb.append(json).append("\n"); System.out.println("insert: "+sb.toString());return sb.toString(); } public String postJson(String httpUrl, String json) {HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPostStringEntity stringEntity = new StringEntity(json, "utf-8");// 解决中文乱码问题stringEntity.setContentEncoding("UTF-8");stringEntity.setContentType("application/json");httpPost.setEntity(stringEntity);return sendHttpPost(httpPost);}
private String sendHttpPost(HttpPost httpPost) { CloseableHttpClient httpClient = null; CloseableHttpResponse response = null; HttpEntity entity = null; String responseContent = null; try { httpClient = HttpClients.createDefault(); response = httpClient.execute(httpPost); entity = response.getEntity(); responseContent = EntityUtils.toString(entity, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } finally { try { if (response != null) { response.close(); } if (httpClient != null) { httpClient.close(); } } catch (IOException e) { e.printStackTrace(); } } return responseContent; }
阅读全文
0 0
- http4client rest buik elasticsearch
- Elasticsearch基础教程 rest api
- elasticsearch rest api操作
- ElasticSearch下的REST接口
- ElasticSearch Rest/RPC 接口解析
- ElasticSearch 中 REST API 详解
- elasticsearch rest API初体验
- Elasticsearch使用REST API实现全文检索
- ElasticSearch第5课之REST API
- Elasticsearch之基础Rest API命令
- elasticsearch的rest api练习记录
- 使用Java Rest Client操作Elasticsearch
- elasticsearch Java High Level REST Client 使用
- ElasticSearch 菜鸟笔记(三)ElasticSearch 常见REST API 操作
- Elasticsearch 5.x (三) Elasticsearch REST API
- Jest is a Java HTTP Rest client for Elasticsearch
- Elasticsearch JAVA API和JAVA REST Clien比较
- elasticsearch源码分析之Rest/RPC 接口解析(八)
- oracle操作字符串:拼接、替换、截取、查找、长度
- 思维导图之探寻墨菲定律
- nrf51822蓝牙芯片ble_app_proximity程序总结
- 编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推。
- linux下设置mysql数据库字符集utf8
- http4client rest buik elasticsearch
- 回文序列
- 【LeetCode】535. Encode and Decode TinyURL
- android实现断点续传
- summernote编辑器插件使用
- 02_选择排序
- Linux安装Mysql
- av_read_frame的过程
- 《人人都是产品经理》——第三章笔记(上)