package com.ylz.es.test;
import com.ylz.es.EsServer;
import com.ylz.es.UserService;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.util.List;
/**
* @Description:
* @Company:易联众技术股份有限公司
* @Author: linwp
* @Date: 2017/6/27 15:39
*/
/*@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-data-es.xml")*/
public class TestDemo {
/* @Autowired
private EsServer esServer;
@Test
public void test(){
esServer.insertOrUpdate();
}*/
@Test
public void tranTest() {
Settings settings = Settings.builder()
.put("client.transport.sniff", true)
.put("cluster.name", "clusterTest")
/* .put("cluster.name", "node-101")*/
.build();
Client client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
//搜索数据
GetResponse response = client.prepareGet("ylz", "medicine", "2472").execute().actionGet();
//输出结果
System.out.println(response.getSourceAsString());
client.close();
}
}
评论5
最新资源