现象:
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 Client
{
public static Client getClient() {
// 1.指定集群名称 2.探测集群中节点状态
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch")
.put("client.transport.sniff", true).build();
Client client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9200));
return client;
}
}
引入了Client类却报错转换异常。
原因:
引入的类名与当前类名重复,均为Client。
解决方案(二选一):
修改当前类名;
指定Client路径,即org.elasticsearch.client.Client client=new TransportClient();