package com.ximua.es4j;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Before;
import org.junit.Test;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ElasticSearch4Java {
private TransportClient client;
private IndexRequest source;
/**
* 获取连接, 第一种方式
* @throws Exception
*/
@Before
public void before() throws Exception {
//设置集群名称
Map<String, String> map = new HashMap<String, String>();
map.put("cluster.name", "elasticsearch");
Settings settings = Settings.builder().put(map).build();
//创建客户端client
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), Integer.parseInt("9300")));
}
/**
* 查看集群信息
*/
@Test
public void NodeHealthInfoTest() {
List<DiscoveryNode> nodes = client.connectedNodes();
for (DiscoveryNode node : nodes) {
System.out.println(node.getHostAddress());
}
}
//api 查询
@Test
public void SearchDocumentTest(){
GetResponse response = client.prepareGet("website","article","1").execute().actionGet();
String result = response.getSourceAsString();
System.out.println(result);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java操作ES5.x api
共70个文件
xml:64个
properties:2个
jsp:1个
需积分: 12 14 下载量 131 浏览量
2018-01-11
16:01:51
上传
评论
收藏 32KB RAR 举报
温馨提示
Java操作ES5.2版本,仅供参考,里面提供两个方法,查询和判断集群状态
资源推荐
资源详情
资源评论
收起资源包目录
es4j_test003.rar (70个子文件)
es4j_test003
pom.xml 1KB
target
classes
com
ximua
es4j
ElasticSearch4Java.class 3KB
log4j2.properties 183B
generated-sources
annotations
es4j_test003.iml 7KB
src
main
webapp
WEB-INF
web.xml 222B
index.jsp 57B
Java
com
ximua
es4j
ElasticSearch4Java.java 2KB
resources
log4j2.properties 183B
.idea
misc.xml 566B
modules.xml 264B
compiler.xml 636B
workspace.xml 34KB
libraries
Maven__org_elasticsearch_plugin_lang_mustache_client_5_3_0.xml 643B
Maven__io_netty_netty_3_10_6_Final.xml 523B
Maven__org_apache_lucene_lucene_sandbox_6_4_1.xml 573B
Maven__org_apache_lucene_lucene_analyzers_common_6_4_1.xml 636B
Maven__org_hdrhistogram_HdrHistogram_2_1_6.xml 555B
Maven__org_apache_lucene_lucene_join_6_4_1.xml 552B
Maven__com_carrotsearch_hppc_0_7_1.xml 499B
Maven__io_netty_netty_common_4_1_7_Final.xml 565B
Maven__org_elasticsearch_securesm_1_1.xml 517B
Maven__org_apache_logging_log4j_log4j_core_2_7.xml 559B
Maven__io_netty_netty_buffer_4_1_7_Final.xml 565B
Maven__junit_junit_4_12.xml 455B
Maven__io_netty_netty_transport_4_1_7_Final.xml 586B
Maven__org_elasticsearch_client_transport_5_3_0.xml 566B
Maven__org_apache_lucene_lucene_spatial_6_4_1.xml 573B
Maven__org_apache_logging_log4j_log4j_api_2_7.xml 552B
Maven__org_apache_lucene_lucene_suggest_6_4_1.xml 573B
Maven__org_apache_httpcomponents_httpclient_4_5_2.xml 577B
Maven__org_yaml_snakeyaml_1_15.xml 495B
Maven__org_apache_lucene_lucene_backward_codecs_6_4_1.xml 629B
Maven__commons_codec_commons_codec_1_10.xml 543B
Maven__net_java_dev_jna_jna_4_2_2.xml 492B
Maven__io_netty_netty_codec_http_4_1_7_Final.xml 593B
Maven__org_apache_lucene_lucene_grouping_6_4_1.xml 580B
Maven__net_sf_jopt_simple_jopt_simple_5_0_2.xml 556B
Maven__joda_time_joda_time_2_9_5.xml 506B
Maven__org_hamcrest_hamcrest_core_1_3.xml 532B
Maven__com_github_spullara_mustache_java_compiler_0_9_3.xml 595B
Maven__org_elasticsearch_plugin_percolator_client_5_3_0.xml 622B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_1_2.xml 644B
Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_yaml_2_8_6.xml 696B
Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_smile_2_8_6.xml 703B
Maven__com_tdunning_t_digest_3_0.xml 497B
Maven__org_apache_httpcomponents_httpasyncclient_4_1_2.xml 612B
Maven__com_fasterxml_jackson_core_jackson_databind_2_1_3.xml 623B
Maven__io_netty_netty_resolver_4_1_7_Final.xml 579B
Maven__org_apache_lucene_lucene_highlighter_6_4_1.xml 601B
Maven__commons_logging_commons_logging_1_1_3.xml 572B
Maven__io_netty_netty_handler_4_1_7_Final.xml 572B
Maven__com_fasterxml_jackson_core_jackson_core_2_8_6.xml 595B
Maven__org_apache_lucene_lucene_misc_6_4_1.xml 552B
Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_cbor_2_8_6.xml 696B
Maven__org_apache_lucene_lucene_core_6_4_1.xml 552B
Maven__org_apache_lucene_lucene_memory_6_4_1.xml 566B
Maven__org_elasticsearch_plugin_transport_netty4_client_5_3_0.xml 664B
Maven__org_apache_lucene_lucene_spatial3d_6_4_1.xml 587B
Maven__org_elasticsearch_plugin_transport_netty3_client_5_3_0.xml 664B
Maven__org_apache_httpcomponents_httpcore_4_4_5.xml 563B
Maven__io_netty_netty_codec_4_1_7_Final.xml 558B
Maven__org_apache_httpcomponents_httpcore_nio_4_4_5.xml 591B
Maven__org_elasticsearch_plugin_reindex_client_5_3_0.xml 601B
Maven__org_apache_lucene_lucene_spatial_extras_6_4_1.xml 622B
Maven__org_apache_lucene_lucene_queryparser_6_4_1.xml 601B
Maven__org_elasticsearch_elasticsearch_5_3_0.xml 566B
Maven__org_apache_lucene_lucene_queries_6_4_1.xml 573B
Maven__org_elasticsearch_client_rest_5_3_0.xml 531B
artifacts
es4j_test003_war_exploded.xml 7KB
es4j_test003_war.xml 302B
inspectionProfiles
共 70 条
- 1
资源评论
一枚程序员
- 粉丝: 30
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python的PCA人脸识别算法的原理及实现代码详解+源码+详细代码解析+开发文档+数据(毕业设计&课程设计&项目开发)
- Decision tree20240105(1).ipynb
- zuoyezuoyezuoye
- zuoyezuoyezuoye
- 机械设计电机转子装配设备sw22非常好的设计图纸100%好用.zip
- 作业作业作业作业作业作业
- xdotool.c
- RLMD鲁棒性局部均值分解信号分量可视化(Matlab完整源码和数据)
- Screenshot_2024-04-26-17-17-26-36_9d26c6446fd7bb8e41d99b6262b17def.jpg
- 6.0版本超广角文件+教程使用MT管理器打-7.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功