资源简介
Elasticsearch5.5.1 JAVA客户端RestClient示例代码,详细介绍:http://blog.csdn.net/u011781521/article/details/77853571
代码片段和文件信息
package com.fendo.RestClient;
import java.io.IOException;
import java.util.Collections;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.junit.Before;
import org.junit.Test;
/**
* Elasticserach RestClient示例
* @author fendo
*
*/
public class Rest {
private static RestClient restClient;
public void getRestClient(){
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY
new UsernamePasswordCredentials(“elastic“ “changeme“));
restClient = RestClient.builder(new HttpHost(“localhost“9200“http“))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}).build();
}
@Before
public void getRest(){
restClient = RestClient.builder(new HttpHost(“localhost“ 9200 “http“)).build();
}
/**
* 查看api信息
* @throws Exception
*/
@Test
public void CatApi() throws Exception{
String method = “GET“;
String endpoint = “/_cat“;
Response response = restClient.performRequest(methodendpoint);
System.out.println(EntityUtils.toString(response.getEntity()));
}
/**
* 创建索引
* @throws Exception
*/
@Test
public void CreateIndex() throws Exception{
String method = “PUT“;
String endpoint = “/test-index“;
Response response = restClient.performRequest(methodendpoint);
System.out.println(EntityUtils.toString(response.getEntity()));
}
/**
* 创建文档
* @throws Exception
*/
@Test
public void CreateDocument()throws Exception{
String method = “PUT“;
String endpoint = “/test-index/test/1“;
HttpEntity entity = new NStringEntity(
“{\n“ +
“ \“user\“ : \“kimchy\“\n“ +
“ \“post_date\“ : \“2009-11-15T14:12:12\“\n“ +
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-09-05 16:26 RestClient\
文件 1024 2017-09-05 16:39 RestClient\.classpath
文件 562 2017-09-05 16:26 RestClient\.project
目录 0 2017-09-05 16:26 RestClient\.settings\
文件 119 2017-09-05 16:26 RestClient\.settings\org.eclipse.core.resources.prefs
文件 736 2017-09-05 16:38 RestClient\.settings\org.eclipse.jdt.core.prefs
文件 90 2017-09-05 16:26 RestClient\.settings\org.eclipse.m2e.core.prefs
文件 2272 2017-09-05 16:48 RestClient\pom.xm
目录 0 2017-09-05 16:26 RestClient\src\
目录 0 2017-09-05 16:26 RestClient\src\main\
目录 0 2017-09-05 16:26 RestClient\src\main\java\
目录 0 2017-09-05 16:26 RestClient\src\main\java\com\
目录 0 2017-09-05 16:26 RestClient\src\main\java\com\fendo\
目录 0 2017-09-05 16:50 RestClient\src\main\java\com\fendo\RestClient\
文件 6883 2017-09-05 16:59 RestClient\src\main\java\com\fendo\RestClient\Rest.java
目录 0 2017-09-05 16:26 RestClient\src\test\
目录 0 2017-09-05 16:26 RestClient\src\test\java\
目录 0 2017-09-05 16:26 RestClient\src\test\java\com\
目录 0 2017-09-05 16:26 RestClient\src\test\java\com\fendo\
目录 0 2017-09-05 16:26 RestClient\src\test\java\com\fendo\RestClient\
文件 686 2017-09-05 16:26 RestClient\src\test\java\com\fendo\RestClient\AppTest.java
目录 0 2017-09-05 16:26 RestClient\target\
目录 0 2017-09-05 16:50 RestClient\target\classes\
目录 0 2017-09-05 16:50 RestClient\target\classes\com\
目录 0 2017-09-05 16:50 RestClient\target\classes\com\fendo\
目录 0 2017-09-05 16:50 RestClient\target\classes\com\fendo\RestClient\
文件 1291 2017-09-05 16:59 RestClient\target\classes\com\fendo\RestClient\Rest$1.class
文件 5462 2017-09-05 16:59 RestClient\target\classes\com\fendo\RestClient\Rest.class
目录 0 2017-09-05 16:50 RestClient\target\classes\me
文件 107 2017-09-05 16:50 RestClient\target\classes\me
目录 0 2017-09-05 16:50 RestClient\target\classes\me
............此处省略9个文件信息
- 上一篇:android欢迎界面源码
- 下一篇:httpclient-4.3.6.jar
相关资源
- NETCFv35.Messages.zh-CHS.wm.cab
- Python AES和Java AES/ECB/PKCS5Padding互转
- java Rest接口服务端简单式Java后台各类
- DES加密文件二进制流
- commons-digester-2.0.jar
- HttpServletRequest源码 HttpServletResponse源码
- Express12.zip
- 智能家居小项目Android+51单片机+ESP82
- JavaDES通过秘钥加密解密Demo
- androidManifest修改工具源代码
- androidManifest修改工具
- recyclerview-v7-26.1.0-sources.jar
- 银行esb开发全过程使用webservice
- 利用Java的动态编译、动态加载结合
- android design.jar包
- AES算法Java实现
- spring-test-4.0.0.RELEASE.jar
- Elasticsearch Java API 手册
- android ChiceScanGun.rar
- android-support-design.jar包 程序文件
- python版DES和MAC算法源码
- SWT表格管理类(包括表头排序,隔行
- android.support.design.jar-24.2.1jar、doc、s
- 128位AES加密算法C语言实现
- Delphi与JAVA互加解密AES算法
- DES加解密ZEROPADDING执行验证无误
- xwork-core-2.2.1-sources.jar 源码
- jspaccess图书馆网站
- java读取properties文件
- sitemesh jar包
评论
共有 条评论