Search in sources :

Example 21 with ClientInterface

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

Example 22 with ClientInterface

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

Example 23 with ClientInterface

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;
        }
    }
}
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