您的位置:首页 > 编程语言 > Java开发

ElasticSearch java API--创建Client连接

2012-11-19 17:36 513 查看
package Client;

import org.elasticsearch.client.Client;

import org.elasticsearch.client.transport.TransportClient;

import org.elasticsearch.common.settings.ImmutableSettings;

import org.elasticsearch.common.settings.Settings;

import org.elasticsearch.common.transport.InetSocketTransportAddress;

public class ServerClient {

public Client getClient(){

Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff",true)
.put("cluster.name", "李安安").build();//clienttransport.sniff:true 嗅探整个集群;cluster.name:xx 集群名称,对应于/config/elasticsearch.yml 内部配置。
Client client=new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("127.0.0.1",9300));
//.addTransportAddress(new InetSocketTransportAddress("192.168.5.1",9300)) 多个连接
return client;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: