验证中...
获取client
Raw Copy
public RestHighLevelClient getClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials upc = new UsernamePasswordCredentials("fantasy", "zw>sguxdn<6o2xz");
credentialsProvider.setCredentials(AuthScope.ANY, upc);
try {
return new RestHighLevelClient(
RestClient.builder(new HttpHost("flow.app.txvpn.net", 17443, "https"))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(
HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}).setMaxRetryTimeoutMillis(200000));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
get请求
Raw Copy
Request request = new Request("GET", "tx_proxyhttp_log-2019.05.08/doc/_search");
String queryString = "{\n" +
" \"query\":{\n" +
" \"range\":{\n" +
" \"timestamp\": {\n" +
" \"gt\":\"2019-05-08T01:07:56+08:00\",\n" +
" \"lt\":\"2019-05-08T01:08:56+08:00\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
HttpEntity entity = new NStringEntity(queryString, ContentType.APPLICATION_JSON);
request.setEntity(entity);
Response response = client.getLowLevelClient().performRequest(request);
String responseBody = EntityUtils.toString(response.getEntity());
System.out.println(responseBody);
post请求
Raw Copy
SearchRequest searchRequest = new SearchRequest("tx_proxyhttp_log-2019.05.08");
searchRequest.types("doc");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchRequest.source(searchSourceBuilder.size(10));
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHits searchHit = response.getHits();
SearchHit[] hits = searchHit.getHits();
for (SearchHit hit : hits) {
System.out.println(hit.getSourceAsMap());
}
System.out.println("size: " + hits.length);

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close