use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ESTest method test.
@Test
public void test() throws Exception {
DefaultApplicationContext context = DefaultApplicationContext.getApplicationContext("conf/elasticsearch.xml");
ElasticSearch elasticSearchSink = context.getTBeanObject("elasticSearch", ElasticSearch.class);
// ElasticSearch restelasticSearchSink = context.getTBeanObject("restelasticSearch", ElasticSearch.class);
ClientInterface clientUtil = elasticSearchSink.getRestClientUtil();
String entity = "{" + "\"aggs\": {" + "\"top_tags\": {" + "\"terms\": {" + "\"field\": \"rpc.keyword\"," + "\"size\": 30" + "}," + "\"aggs\": {" + "\"top_sales_hits\": {" + "\"top_hits\": {" + "\"sort\": [" + "{" + "\"collectorAcceptTime\": {" + "\"order\": \"desc\"" + "}" + "}" + "]," + "\"_source\": {" + "\"includes\": [ \"collectorAcceptTime\", \"rpc\" ]" + "}," + "\"size\" : 1" + "}" + "}" + "}" + "}" + "}" + "}";
String response = (String) clientUtil.executeRequest("trace-*/_search?size=0", entity);
System.out.println(response);
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ESTest method testBulkAddDateDocument.
@Test
public void testBulkAddDateDocument() throws ParseException {
testGetmapping();
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
String date = format.format(new Date());
ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
List<Demo> demos = new ArrayList<Demo>();
Demo demo = new Demo();
demo.setDemoId(2l);
demo.setAgentStarttime(new Date());
demo.setApplicationName("blackcatdemo2");
demo.setContentbody("this is content body2");
demos.add(demo);
demo = new Demo();
demo.setDemoId(3l);
demo.setAgentStarttime(new Date());
demo.setApplicationName("blackcatdemo3");
demo.setContentbody("this is content body3");
demos.add(demo);
// 创建模板
String response = // 索引表
clientUtil.addDateDocuments(// 索引表
"demo", // 索引类型
"demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
"createDemoDocument", demos);
System.out.println("addDateDocument-------------------------");
System.out.println(response);
response = // 索引表
clientUtil.getDocument(// 索引表
"demo-" + date, // 索引类型
"demo", "2");
System.out.println("getDocument-------------------------");
System.out.println(response);
demo = // 索引表
clientUtil.getDocument(// 索引表
"demo-" + date, // 索引类型
"demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
"3", Demo.class);
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ElasticSearch method getConfigRestClientUtil.
public ClientInterface getConfigRestClientUtil(String configFile) {
ClientInterface clientInterface = configClientUtis.get(configFile);
if (clientInterface != null)
return clientInterface;
else {
if (restClient != null) {
synchronized (configClientUtis) {
clientInterface = configClientUtis.get(configFile);
if (clientInterface != null)
return clientInterface;
clientInterface = this.restClient.getConfigClientUtil(this.indexNameBuilder, configFile);
configClientUtis.put(configFile, clientInterface);
return clientInterface;
}
} else {
return null;
}
}
}
Aggregations