Search in sources :

Example 16 with ClientInterface

use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.

the class ESTest method testBulkAddDateDocumentByTemplate.

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

Example 17 with ClientInterface

use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.

the class ESTest method cleanAllXPackIndices.

@Test
public void cleanAllXPackIndices() {
    // ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil();
    // clientInterface.cleanAllXPackIndices();
    ClientInterface eventClientUtil = ElasticSearchHelper.getRestClientUtil();
    System.out.println(eventClientUtil.getIndice(".security"));
    System.out.println(eventClientUtil.cleanAllXPackIndices());
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Test(org.junit.Test)

Example 18 with ClientInterface

use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.

the class ESTest method testBulkAddDocumentByTemplate.

@Test
public void testBulkAddDocumentByTemplate() {
    testCreateDemoMapping();
    String response = null;
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
    List<Demo> demos = new ArrayList<>();
    long starttime = System.currentTimeMillis();
    for (int j = 0; j < 1; j++) {
        int start = j * 10000;
        for (int i = start; i < 10000 + start; i++) {
            Demo demo = new Demo();
            demo.setDemoId(i);
            demo.setAgentStarttime(new Date());
            demo.setApplicationName("blackcatdemo" + i);
            demo.setContentbody("this is content body中文" + i);
            demos.add(demo);
        }
        // 创建文档
        response = // 索引表
        clientUtil.addDocuments(// 索引表
        "demo", // 索引类型
        "demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
        "createDemoDocument", demos);
        System.out.println("addDateDocument-------------------------");
        System.out.println(response);
        demos.clear();
    }
    long endtime = System.currentTimeMillis();
    System.out.println(endtime - starttime);
// 
// response = clientUtil.getDocument("demo",//索引表
// "demo",//索引类型
// "2");
// System.out.println("getDocument-------------------------");
// System.out.println(response);
// 
// Demo demo = clientUtil.getDocument("demo",//索引表
// "demo",//索引类型
// "3",//创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
// Demo.class);
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Test(org.junit.Test)

Example 19 with ClientInterface

use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.

the class ESTest method testAddDateDocument.

@Test
public void testAddDateDocument() throws ParseException {
    testGetmapping();
    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
    String date = format.format(new Date());
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
    Demo demo = new Demo();
    demo.setDemoId(5l);
    demo.setAgentStarttime(new Date());
    demo.setApplicationName("blackcatdemo");
    demo.setContentbody("this is content body");
    org.joda.time.format.DateTimeParserBucket s;
    // 创建模板
    String response = // 索引表
    clientUtil.addDateDocument(// 索引表
    "demo", // 索引类型
    "demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
    "createDemoDocument", demo);
    System.out.println("addDateDocument-------------------------");
    System.out.println(response);
    response = // 索引表
    clientUtil.getDocument(// 索引表
    "demo-" + date, // 索引类型
    "demo", "5");
    System.out.println("getDocument-------------------------");
    System.out.println(response);
    demo = // 索引表
    clientUtil.getDocument(// 索引表
    "demo-" + date, // 索引类型
    "demo", // 创建文档对应的脚本名称,在estrace/ESTracesMapper.xml中配置
    "5", Demo.class);
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 20 with ClientInterface

use of org.frameworkset.elasticsearch.client.ClientInterface in project bboss-elastic by bbossgroups.

the class ESTest method testCreateTempate.

@Test
public void testCreateTempate() throws ParseException {
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTemplate.xml");
    // 创建模板
    String response = // 模板名称
    clientUtil.createTempate(// 模板名称
    "demotemplate_1", // 模板对应的脚本名称,在estrace/ESTemplate.xml中配置
    "demoTemplate");
    System.out.println("createTempate-------------------------");
    System.out.println(response);
    // 获取模板
    /**
     * 指定模板
     * /_template/demoTemplate_1
     * /_template/demoTemplate*
     * 所有模板 /_template
     */
    String template = clientUtil.executeHttp("/_template/demotemplate_1", ClientUtil.HTTP_GET);
    System.out.println("HTTP_GET-------------------------");
    System.out.println(template);
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Test(org.junit.Test)

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