Java Code Examples for org.frameworkset.elasticsearch.client.ClientInterface#executeRequest()
The following examples show how to use
org.frameworkset.elasticsearch.client.ClientInterface#executeRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESTest.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
@Test public void testConfig() throws ParseException{ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/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 ; } }
Example 2
Source File: ESTest.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
@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 ; } }
Example 3
Source File: ESTest.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
@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 ; } }
Example 4
Source File: ESTest.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
public void testConfig() throws ParseException{ // ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("traceElasticSearch",//可以指定elasticSearch服务器 // "esmapper/estrace/ESTracesMapper.xml"); ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/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 ; } }
Example 5
Source File: ESTest.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
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 ; } }
Example 6
Source File: ESTest.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: ESTest.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
@Test public void querey() 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 entiry = "{\"query\" : {\"term\" : { \"rpc\" : \"content.page\" }}}"; String response = (String) clientUtil.executeRequest("trace-*/_search",entiry); System.out.println(response); }
Example 8
Source File: ESTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
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); }
Example 9
Source File: ESTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
public void querey() 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 entiry = "{\"query\" : {\"term\" : { \"rpc\" : \"content.page\" }}}"; String response = (String) clientUtil.executeRequest("trace-*/_search",entiry); System.out.println(response); }
Example 10
Source File: ElasticSearch.java From bboss-elasticsearch with Apache License 2.0 | 4 votes |
public Object executeRequest(String path, String entity) throws Exception { ClientInterface clientUtil = this.getRestClientUtil(); return clientUtil.executeRequest(path, entity); }
Example 11
Source File: ESTest.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
public void testCondition() throws ParseException{ TraceESDao traceESDao = new TraceESDao(); // 响应报文 // 开始时间 TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); traceExtraCriteria.setStartTime(dateFormat.parse("2017-10-24 00:00:00").getTime()); traceExtraCriteria.setEndTime(dateFormat.parse("2017-11-28 23:00:00").getTime()); // 查询条件 String queryCondition = "/testweb/admin/content.page"; // 查询状态:all 全部 success 处理成功 fail 处理失败 String queryStatus = "all"; if(queryCondition != null){ queryCondition = ResultUtil.handleElasticSearchSpecialChars(queryCondition); // queryCondition = queryCondition.replace("-","\\\\-"); //queryCondition = ClientUtil.handleElasticSearchSpecialChars(queryCondition); } String queryAction = null; if(queryAction == null ) queryAction = "trace"; traceExtraCriteria.setQueryAction(queryAction); traceExtraCriteria.setQueryCondition(queryCondition); traceExtraCriteria.setQueryStatus(queryStatus); traceExtraCriteria.setApplication("testweb88"); traceExtraCriteria.setOrderBy("time"); ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/ESTracesMapper.xml"); String retString = clientUtil.executeRequest("trace-*/_search?explain","queryServiceByCondition",traceExtraCriteria); System.out.println(retString); retString = clientUtil.executeRequest("trace-*/_search","queryServiceByCondition",traceExtraCriteria); System.out.println(retString); //全文检索结果 ESDatas<Traces> response = clientUtil.searchList("trace-*/_search","queryServiceByCondition",traceExtraCriteria,Traces.class); //精确检索 traceExtraCriteria.setExactSearch(true); traceExtraCriteria.setSearchFields(new String[]{"rpc"}); response = clientUtil.searchList("trace-*/_search","exactQueryServiceByCondition",traceExtraCriteria,Traces.class); JsonDataResult ret = new JsonDataResult(); ret.setData(response.getDatas()); ret.setTotalSize(response.getTotalSize()); if(response.getAggregations() != null) { /** * "key_as_string": "2017-09-22T14:30:00.000+08:00", "key": 1506061800000, "doc_count": 1 */ List<Map<String, Object>> traces_date_histogram = (List<Map<String, Object>>) response.getAggregations().get("traces_date_histogram").get("buckets"); ret.setDateHistogram(traces_date_histogram); } System.out.println(); }
Example 12
Source File: TraceESDaoTest.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
@Test public void testCondition() throws ParseException{ TraceESDao traceESDao = new TraceESDao(); // 响应报文 // 开始时间 org.frameworkset.elasticsearch.TraceExtraCriteria traceExtraCriteria = new org.frameworkset.elasticsearch.TraceExtraCriteria(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); traceExtraCriteria.setStartTime(dateFormat.parse("2017-10-24 00:00:00").getTime()); traceExtraCriteria.setEndTime(dateFormat.parse("2017-11-28 23:00:00").getTime()); // 查询条件 String queryCondition = "/testweb/admin/content.page"; // 查询状态:all 全部 success 处理成功 fail 处理失败 String queryStatus = "all"; if(queryCondition != null){ queryCondition = ResultUtil.handleElasticSearchSpecialChars(queryCondition); // queryCondition = queryCondition.replace("-","\\\\-"); //queryCondition = ClientUtil.handleElasticSearchSpecialChars(queryCondition); } String queryAction = null; if(queryAction == null ) queryAction = "trace"; traceExtraCriteria.setQueryAction(queryAction); traceExtraCriteria.setQueryCondition(queryCondition); traceExtraCriteria.setQueryStatus(queryStatus); traceExtraCriteria.setApplication("testweb88"); traceExtraCriteria.setOrderBy("time"); ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/ESTracesMapper.xml"); String retString = clientUtil.executeRequest("trace-*/_search?explain","queryServiceByCondition",traceExtraCriteria); System.out.println(retString); retString = clientUtil.executeRequest("trace-*/_search","queryServiceByCondition",traceExtraCriteria); System.out.println(retString); //全文检索结果 ESDatas<Traces> response = clientUtil.searchList("trace-*/_search","queryServiceByCondition",traceExtraCriteria,Traces.class); //精确检索 traceExtraCriteria.setExactSearch(true); traceExtraCriteria.setSearchFields(new String[]{"rpc"}); response = clientUtil.searchList("trace-*/_search","exactQueryServiceByCondition",traceExtraCriteria,Traces.class); JsonDataResult ret = new JsonDataResult(); ret.setData(response.getDatas()); ret.setTotalSize(response.getTotalSize()); if(response.getAggregations() != null) { /** * "key_as_string": "2017-09-22T14:30:00.000+08:00", "key": 1506061800000, "doc_count": 1 */ List<Map<String, Object>> traces_date_histogram = (List<Map<String, Object>>) response.getAggregations().get("traces_date_histogram").get("buckets"); ret.setDateHistogram(traces_date_histogram); } System.out.println(); }
Example 13
Source File: TraceESDaoTest.java From elasticsearch-gradle-example with Apache License 2.0 | 3 votes |
@Test public void testaaa(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/ESTracesMapper.xml"); String ddd = clientUtil.executeRequest("/trace-*/_search","testaaa",(Object)null); RestResponse result = clientUtil.executeRequest("/trace-*/_search","testaaa",(Object)null, new ElasticSearchResponseHandler( TraceScatter.class)); System.out.println(ddd); }