use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ESTest method testBulkAddAndUpdateDateDocuments.
@Test
public void testBulkAddAndUpdateDateDocuments() throws ParseException {
testCreateDemoMapping();
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
String date = format.format(new Date());
ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
List<Demo> demos = new ArrayList<>();
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", demos);
System.out.println("addDateDocument-------------------------");
System.out.println(response);
// 批量更新文档
demo.setContentbody("updated");
response = clientUtil.updateDocuments("demo-" + date, "demo", demos);
System.out.println("updateDateDocument-------------------------");
System.out.println(response);
response = // 索引表
clientUtil.getDocument(// 索引表
"demo-" + date, // 索引类型
"demo", // 文档id
"2");
System.out.println("getDocument-------------------------");
System.out.println(response);
demo = // 索引表
clientUtil.getDocument(// 索引表
"demo-" + date, // 索引类型
"demo", // 文档id
"3", Demo.class);
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ESTest method testAddDocument.
@Test
public void testAddDocument() throws ParseException {
testCreateDemoMapping();
ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
Demo demo = new Demo();
demo.setDemoId(5l);
demo.setAgentStarttime(new Date());
demo.setApplicationName("blackcatdemo");
demo.setContentbody(FileUtil.getFileContent(new File("E:/workspace/bbossgroups/bboss-elastic/bboss-elasticsearch-rest/src/test/java/org/frameworkset/elasticsearch/ESTest.java")));
// 创建文档
String response = // 索引表
clientUtil.addDocument(// 索引表
"demo", // 索引类型
"demo", demo);
System.out.println("addDateDocument-------------------------");
System.out.println(response);
response = // 索引表
clientUtil.getDocument(// 索引表
"demo", // 索引类型
"demo", // 文档id
"5");
System.out.println("getDocument-------------------------");
System.out.println(response);
demo = // 索引表
clientUtil.getDocument(// 索引表
"demo", // 索引类型
"demo", // 文档id
"5", Demo.class);
// 删除索引文档
// 索引表
clientUtil.deleteDocument(// 索引表
"demo", // 索引类型
"demo", // 文档id
"5");
// 批量删除索引文档
// 索引表
clientUtil.deleteDocuments(// 索引表
"demo", // 索引类型
"demo", "1", "2", // 文档ids
"3");
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ESTest method testAddDocumentByTemplate.
@Test
public void testAddDocumentByTemplate() throws ParseException {
testCreateDemoMapping();
org.apache.http.impl.io.SessionInputBufferImpl s;
SocketConfig dd;
ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
Demo demo = new Demo();
demo.setDemoId(5l);
demo.setAgentStarttime(new Date());
demo.setApplicationName("blackcatdemo");
demo.setContentbody(FileUtil.getFileContent(new File("E:/workspace/bbossgroups/bboss-elastic/bboss-elasticsearch-rest/src/test/java/org/frameworkset/elasticsearch/ESTest.java")));
// 创建文档
String response = // 索引表
clientUtil.addDocument(// 索引表
"demo", // 索引类型
"demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
"createDemoDocument", demo);
System.out.println("addDateDocument-------------------------");
System.out.println(response);
response = // 索引表
clientUtil.getDocument(// 索引表
"demo", // 索引类型
"demo", "5");
System.out.println("getDocument-------------------------");
System.out.println(response);
demo = // 索引表
clientUtil.getDocument(// 索引表
"demo", // 索引类型
"demo", // 文档id
"5", Demo.class);
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class TestSerialUtil method test.
@Test
public void test() {
JsonObj jsonObj = new JsonObj();
jsonObj.setId("2");
jsonObj.setAgentStarttime(new Date());
jsonObj.setApplicationName("sss");
ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil();
clientInterface.addDocument("testserial", "testserial", jsonObj);
jsonObj = clientInterface.getDocument("testserial", "testserial", "2", JsonObj.class);
System.out.println(SerialUtil.object2json(jsonObj));
jsonObj = SimpleStringUtil.json2Object(SerialUtil.object2json(jsonObj), JsonObj.class);
// DateFormateMeta dateFormateMeta = DateFormateMeta.buildDateFormateMeta("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",null,"UTC");
// System.out.println(dateFormateMeta.toDateFormat().format(jsonObj.getAgentStarttime()));
}
use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.
the class ElasticSearch method getConfigRestClientUtil.
public ClientInterface getConfigRestClientUtil(BaseTemplateContainerImpl templateContainer) {
ClientInterface clientInterface = configClientUtis.get(templateContainer.getNamespace());
if (clientInterface != null)
return clientInterface;
else {
if (restClient != null) {
synchronized (configClientUtis) {
clientInterface = configClientUtis.get(templateContainer.getNamespace());
if (clientInterface != null)
return clientInterface;
clientInterface = this.restClient.getConfigClientUtil(this.indexNameBuilder, templateContainer);
configClientUtis.put(templateContainer.getNamespace(), clientInterface);
return clientInterface;
}
} else {
return null;
}
}
}
Aggregations