Search in sources :

Example 1 with ClientInterface

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);
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 2 with ClientInterface

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");
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) File(java.io.File) Test(org.junit.Test)

Example 3 with ClientInterface

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);
}
Also used : SocketConfig(org.apache.http.config.SocketConfig) ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) File(java.io.File) Test(org.junit.Test)

Example 4 with ClientInterface

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()));
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Date(java.util.Date) Test(org.junit.Test)

Example 5 with ClientInterface

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;
        }
    }
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface)

Aggregations

ClientInterface (org.frameworkset.elasticsearch.client.ClientInterface)23 Test (org.junit.Test)21 SimpleDateFormat (java.text.SimpleDateFormat)9 DateFormat (java.text.DateFormat)3 ESMapResponseHandler (org.frameworkset.elasticsearch.handler.ESMapResponseHandler)3 ESStringResponseHandler (org.frameworkset.elasticsearch.handler.ESStringResponseHandler)3 FastDateFormat (org.frameworkset.util.FastDateFormat)3 File (java.io.File)2 DefaultApplicationContext (org.frameworkset.spi.DefaultApplicationContext)2 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SocketConfig (org.apache.http.config.SocketConfig)1 ConfigRestClientUtil (org.frameworkset.elasticsearch.client.ConfigRestClientUtil)1 IndexField (org.frameworkset.elasticsearch.entity.IndexField)1