Search in sources :

Example 11 with ClientInterface

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

the class ESTest method testSearh.

@Test
public void testSearh() throws ParseException {
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("org/frameworkset/elasticsearch/ESTracesMapper.xml");
    TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria();
    traceExtraCriteria.setApplication("testweb1");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    traceExtraCriteria.setStartTime(dateFormat.parse("2017-09-02 00:00:00").getTime());
    traceExtraCriteria.setEndTime(dateFormat.parse("2017-09-10 00:00:00").getTime());
    String data = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESStringResponseHandler());
    System.out.println("------------------------------");
    System.out.println(data);
    System.out.println("------------------------------");
    Map<String, Object> response = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESMapResponseHandler());
    if (response.containsKey("error")) {
        return;
    }
}
Also used : ESMapResponseHandler(org.frameworkset.elasticsearch.handler.ESMapResponseHandler) FastDateFormat(org.frameworkset.util.FastDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) ESStringResponseHandler(org.frameworkset.elasticsearch.handler.ESStringResponseHandler) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 12 with ClientInterface

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

the class ESTest method testSearhHits.

@Test
public void testSearhHits() throws ParseException {
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("org/frameworkset/elasticsearch/ESTracesMapper.xml");
    TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria();
    traceExtraCriteria.setApplication("testweb1");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    traceExtraCriteria.setStartTime(dateFormat.parse("2017-09-02 00:00:00").getTime());
    traceExtraCriteria.setEndTime(dateFormat.parse("2017-09-10 00:00:00").getTime());
    String data = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESStringResponseHandler());
    System.out.println("------------------------------");
    System.out.println(data);
    System.out.println("------------------------------");
    Map<String, Object> response = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESMapResponseHandler());
    if (response.containsKey("error")) {
        return;
    }
}
Also used : ESMapResponseHandler(org.frameworkset.elasticsearch.handler.ESMapResponseHandler) FastDateFormat(org.frameworkset.util.FastDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) ESStringResponseHandler(org.frameworkset.elasticsearch.handler.ESStringResponseHandler) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 13 with ClientInterface

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

the class ESTest method testTempate.

@Test
public void testTempate() 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);
    // 删除模板
    template = clientUtil.executeHttp("/_template/demotemplate_1", ClientUtil.HTTP_DELETE);
    System.out.println("HTTP_DELETE-------------------------");
    System.out.println(template);
    template = clientUtil.executeHttp("/_template/demotemplate_1", ClientUtil.HTTP_GET);
    System.out.println("HTTP_GET after delete-------------------------");
    System.out.println(template);
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Test(org.junit.Test)

Example 14 with ClientInterface

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

the class ESTest method testCreateDemoMapping.

@Test
public void testCreateDemoMapping() {
    ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
    try {
        // 获取索引表结构
        System.out.println(clientUtil.getIndice("demo"));
        // 删除索引表结构
        System.out.println(clientUtil.dropIndice("demo"));
    } catch (ElasticSearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // 创建索引表结构
    System.out.println(clientUtil.createIndiceMapping("demo", "createDemoIndice"));
    System.out.println(clientUtil.getIndice("demo"));
    System.out.println(clientUtil.getIndice("demo"));
    System.out.println(clientUtil.getIndice("demo"));
}
Also used : ClientInterface(org.frameworkset.elasticsearch.client.ClientInterface) Test(org.junit.Test)

Example 15 with ClientInterface

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

the class ESTest method testAddDateDocumentByTemplate.

@Test
public void testAddDateDocumentByTemplate() 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");
    // 创建模板
    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)

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