Java Code Examples for org.frameworkset.elasticsearch.ElasticSearchHelper#getConfigRestClientUtil()
The following examples show how to use
org.frameworkset.elasticsearch.ElasticSearchHelper#getConfigRestClientUtil() .
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: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
/** * 检索公司信息,并返回公司对应的雇员信息(符合检索条件的雇员信息) */ public void hasChildSearchReturnParent2ndChildren(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("name","Alice Smith"); try { ESInnerHitSerialThreadLocal.setESInnerTypeReferences("employee",Employee.class);//指定inner查询结果对于雇员类型 // ESInnerHitSerialThreadLocal.setESInnerTypeReferences("othersontype",OtherSon.class);//指定inner查询结果对于雇员类型 ESDatas<Company> escompanys = clientUtil.searchList("company/company/_search", "hasChildSearchReturnParent2ndChildren",params,Company.class); long totalSize = escompanys.getTotalSize(); List<Company> companyList = escompanys.getDatas();//获取符合条件的公司 //查看公司下面的雇员信息(符合检索条件的雇员信息) for (int i = 0; i < companyList.size(); i++) { Company company = companyList.get(i); List<Employee> employees = ResultUtil.getInnerHits(company.getInnerHits(), "employee"); System.out.println(employees.size()); // List<OtherSon> otherSons = ResultUtil.getInnerHits(company.getInnerHits(), "othersontype"); // System.out.println(otherSons.size()); } } finally{ ESInnerHitSerialThreadLocal.clean();//清空inner查询结果对于雇员类型 } }
Example 2
Source File: SuggestionTest.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
@Test public void testCreateSuggestion(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/suggest.xml"); try { clientUtil.dropIndice("book"); String template = clientUtil.createIndiceMapping("book","createCompleteSuggestBookIndice"); System.out.println(template); template = clientUtil.getIndexMapping("book"); System.out.println(template); } catch (ElasticSearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example 3
Source File: TestByQuery.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
public void deleteByQuery(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/byquery.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("country","UK"); //先查询数据是否存在 ESDatas<Employee> escompanys = clientUtil.searchList("company/employee/_search","deleteByQuery",params,Employee.class); List<Employee> companyList = escompanys.getDatas();//获取符合UK国家条件的公司的员工信息 long totalSize = escompanys.getTotalSize(); if(companyList != null && companyList.size() > 0) {//如果有雇员信息,则删除之 String result = clientUtil.deleteByQuery("company/employee/_delete_by_query?scroll_size=5000", "deleteByQuery", params); System.out.println(result); //删除后再次查询,验证数据是否被删除 escompanys = clientUtil.searchList("company/employee/_search","deleteByQuery",params,Employee.class); companyList = escompanys.getDatas();//获取符合UK国家条件的公司的员工信息 totalSize = escompanys.getTotalSize(); System.out.println("删除后再次查询,验证数据是否被删除:totalSize="+totalSize); } }
Example 4
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过雇员姓名检索公司信息 */ public void hasChildSearchByName(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("name","Alice Smith"); ESDatas<Company> escompanys = clientUtil.searchList("company/company/_search","hasChildSearchByName",params,Company.class); List<Company> companyList = escompanys.getDatas();//获取符合条件的公司 long totalSize = escompanys.getTotalSize(); }
Example 5
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过雇员生日检索公司信息 */ public void hasChildSearchByBirthday(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("birthday","1980-01-01"); ESDatas<Company> escompanys = clientUtil.searchList("company/company/_search","hasChildSearchByBirthday",params,Company.class); List<Company> companyList = escompanys.getDatas();//获取符合条件的公司 long totalSize = escompanys.getTotalSize(); }
Example 6
Source File: License.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
public static void main(String[] args){ ClientInterface eventClientUtil = ElasticSearchHelper.getConfigRestClientUtil("conf/license.xml"); String ttt = eventClientUtil.executeHttp("_xpack/license?acknowledge=true","license", ClientUtil.HTTP_PUT); // System.out.println(ttt); logger.info(ttt); System.exit(1); }
Example 7
Source File: ElasticsearchExecutorIT.java From pinpoint with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { // BBoss support elasticsearch 1.x,2.x,5.x,6.x,7.x,+ // and we use elasticsearch 6.3.0 to test the Elasticsearch BBoss client plugin. // BBoss connect elasticsearch use localhost and http port 9200 default. // Here is a bboss web demo base spring boot and elasticsearch 5.x,6.x,7.x,8.x: // https://github.com/bbossgroups/es_bboss_web // // Here is a quickstart tutorial: // https://esdoc.bbossgroups.com/#/quickstart embeddedElastic = EmbeddedElastic.builder() .withElasticVersion("6.8.0") .withSetting(PopularProperties.HTTP_PORT, 9200) .withEsJavaOpts("-Xms128m -Xmx512m") .withStartTimeout(2, MINUTES) .build() .start(); //Build a elasticsearch client instance(Return a single instance but multithreaded security) with dsl config file elasticsearchbboss/car-mapping.xml. configRestClientInterface = ElasticSearchHelper.getConfigRestClientUtil("elasticsearchbboss/car-mapping.xml"); // Create an elasticsearch client interface instance with a specific Elasticserch datasource name and with dsl config file elasticsearchbboss/car-mapping.xml. //configRestClientInterface = ElasticSearchHelper.getConfigRestClientUtil("esdatasourceName","elasticsearchbboss/car-mapping.xml"); //build a elasticsearch client instance(Return a single instance but multithreaded security) for do not need dsl or direct dsl operations. clientInterface = ElasticSearchHelper.getRestClientUtil(); // Create an elasticsearch client interface instance with a specific Elasticserch datasource name //clientInterface = ElasticSearchHelper.getRestClientUtil("esdatasourceName"); // A multidatasource spring boot demo: https://github.com/bbossgroups/es_bboss_web/tree/multiesdatasource }
Example 8
Source File: PhraseSuggestionTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
@Test public void testPhraseSuggest(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/suggest.xml"); String template = clientUtil.getIndexMapping("test"); System.out.println(template); String response = clientUtil.executeHttp("test/_search?pretty","phraseSearch", ClientUtil.HTTP_POST); System.out.println(response); PhraseRestResponse book = clientUtil.phraseSuggest("test/_search", "phraseSearch") ; Map<String, List<PhraseSuggest>> phraseSuggests = book.getSuggests(); System.out.println(); }
Example 9
Source File: SuggestionTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
@Test public void testCompleteSuggest(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/suggest.xml"); String template = clientUtil.getIndexMapping("book"); System.out.println(template); String mapping = clientUtil.getIndexMapping("book"); String response = clientUtil.executeHttp("book/_search?pretty","complateSuggestSearch", ClientUtil.HTTP_POST); System.out.println(response); CompleteRestResponse book = clientUtil.complateSuggest("book/_search", "complateSuggestSearch",Book.class) ; Map<String, List<CompleteSuggest>> completeSuggests = book.getSuggests(); System.out.println(); }
Example 10
Source File: SuggestionTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
@Test public void testTermSuggest(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/suggest.xml"); String template = clientUtil.getIndexMapping("book"); System.out.println(template); String mapping = clientUtil.getIndexMapping("book"); String response = clientUtil.executeHttp("book/_search?pretty","termSearch", ClientUtil.HTTP_POST); System.out.println(response); TermRestResponse book = clientUtil.termSuggest("book/_search", "termSearch") ; Map<String, List<TermSuggest>> termSuggests = book.getSuggests(); System.out.println(); }
Example 11
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
public void createClientIndice(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/Client_Info.xml"); try { //删除mapping clientUtil.dropIndice("client_info"); } catch (ElasticSearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } //创建mapping clientUtil.createIndiceMapping("client_info","createClientIndice"); }
Example 12
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 查找顾客信息,演示多子文档父子数据查询功能 */ public void hasParentSearchByCountryReturnParent2ndMultiChildren(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/Client_Info.xml"); Map<String,Object> params = new HashMap<String,Object>();//没有检索条件,构造一个空的参数对象 // params.put("name","Alice Smith"); try { //设置子文档的类型和对象映射关系 ESInnerHitSerialThreadLocal.setESInnerTypeReferences("exam",Exam.class);//指定inner查询结果对于exam类型和对应的对象类型Exam ESInnerHitSerialThreadLocal.setESInnerTypeReferences("diagnosis",Diagnosis.class);//指定inner查询结果对于diagnosis类型和对应的对象类型Diagnosis ESInnerHitSerialThreadLocal.setESInnerTypeReferences("medical",Medical.class);//指定inner查询结果对于medical类型和对应的对象类型Medical ESDatas<Basic> escompanys = clientUtil.searchList("client_info/basic/_search", "hasParentSearchByCountryReturnParent2ndMultiChildren",params,Basic.class); // escompanys = clientUtil.searchAll("client_info",Basic.class); long totalSize = escompanys.getTotalSize(); List<Basic> clientInfos = escompanys.getDatas();//获取符合条件的数据 //查看公司下面的雇员信息(符合检索条件的雇员信息) for (int i = 0; clientInfos != null && i < clientInfos.size(); i++) { Basic clientInfo = clientInfos.get(i); List<Exam> exams = ResultUtil.getInnerHits(clientInfo.getInnerHits(), "exam"); if(exams != null) System.out.println(exams.size()); List<Diagnosis> diagnosiss = ResultUtil.getInnerHits(clientInfo.getInnerHits(), "diagnosis"); if(diagnosiss != null) System.out.println(diagnosiss.size()); List<Medical> medicals = ResultUtil.getInnerHits(clientInfo.getInnerHits(), "medical"); if(medicals != null) System.out.println(medicals.size()); } } finally{ ESInnerHitSerialThreadLocal.clean();//清空inner查询结果对于雇员类型 } }
Example 13
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
public void createIndice(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); try { //删除mapping clientUtil.dropIndice("company"); } catch (ElasticSearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } //创建mapping clientUtil.createIndiceMapping("company","createCompanyEmployeeIndice"); }
Example 14
Source File: SuggestionTest.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
@Test public void testCount(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/suggest.xml"); MapRestResponse response = clientUtil.search("book/_count?pretty", "count") ; System.out.println(response.getCount()); }
Example 15
Source File: TestScrollQuery.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
/** * 并行方式执行slice scroll操作 */ @Test public void testParralSliceScroll() { final ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/scroll.xml"); final List<String> scrollIds = new ArrayList<>(); long starttime = System.currentTimeMillis(); //scroll slice分页检索 final int max = 6; final CountDownLatch countDownLatch = new CountDownLatch(max);//线程任务完成计数器,每个线程对应一个sclice,每运行完一个slice任务,countDownLatch计数减去1 for (int j = 0; j < max; j++) { final int i = j; Thread sliceThread = new Thread(new Runnable() {//多线程并行执行scroll操作做,每个线程对应一个sclice @Override public void run() { Map params = new HashMap(); params.put("id", i); params.put("max", max);//最多6个slice,不能大于share数 params.put("size", 100);//每页100条记录 ESDatas<Map> sliceResponse = clientUtil.searchList("agentstat-*/_search?scroll=1m", "scrollSliceQuery", params,Map.class); List<Map> sliceDatas = sliceResponse.getDatas(); incrementSize( sliceDatas.size());//统计实际处理的文档数量 long totalSize = sliceResponse.getTotalSize(); String scrollId = sliceResponse.getScrollId(); if (scrollId != null) scrollIds.add(scrollId); System.out.println("totalSize:" + totalSize); System.out.println("scrollId:" + scrollId); if (sliceDatas != null && sliceDatas.size() >= 100) {//每页100条记录,迭代scrollid,遍历scroll分页结果 do { sliceResponse = clientUtil.searchScroll("1m", scrollId, Map.class); String sliceScrollId = sliceResponse.getScrollId(); if (sliceScrollId != null) scrollIds.add(sliceScrollId); sliceDatas = sliceResponse.getDatas(); if (sliceDatas == null || sliceDatas.size() < 100) { break; } incrementSize( sliceDatas.size());//统计实际处理的文档数量 } while (true); } countDownLatch.countDown();//slice检索完毕后计数器减1 } }); sliceThread.start(); } try { countDownLatch.await();//等待所有的线程执行完毕,计数器变成0 } catch (InterruptedException e) { e.printStackTrace(); } long endtime = System.currentTimeMillis(); System.out.println("耗时:"+(endtime - starttime)+",realTotalSize:"+realTotalSize); //查询存在es服务器上的scroll上下文信息 String scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); // System.out.println(scrolls); //处理完毕后清除scroll上下文信息 if(scrollIds.size() > 0) { scrolls = clientUtil.deleteScrolls(scrollIds); // System.out.println(scrolls); } //清理完毕后查看scroll上下文信息 scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); // System.out.println(scrolls); }
Example 16
Source File: TestScrollQuery.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
/** * 串行方式执行slice scroll操作 */ @Test public void testSliceScroll() { ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/scroll.xml"); List<String> scrollIds = new ArrayList<>(); long starttime = System.currentTimeMillis(); //scroll slice分页检索 int max = 6; long realTotalSize = 0; for (int i = 0; i < max; i++) { Map params = new HashMap(); params.put("id", i); params.put("max", max);//最多6个slice,不能大于share数 params.put("size", 100);//每页100条记录 ESDatas<Map> sliceResponse = clientUtil.searchList("agentstat-*/_search?scroll=1m", "scrollSliceQuery", params,Map.class); List<Map> sliceDatas = sliceResponse.getDatas(); realTotalSize = realTotalSize + sliceDatas.size(); long totalSize = sliceResponse.getTotalSize(); String scrollId = sliceResponse.getScrollId(); if (scrollId != null) scrollIds.add(scrollId); System.out.println("totalSize:" + totalSize); System.out.println("scrollId:" + scrollId); if (sliceDatas != null && sliceDatas.size() >= 100) {//每页100条记录,迭代scrollid,遍历scroll分页结果 do { sliceResponse = clientUtil.searchScroll("1m", scrollId, Map.class); String sliceScrollId = sliceResponse.getScrollId(); if (sliceScrollId != null) scrollIds.add(sliceScrollId); sliceDatas = sliceResponse.getDatas(); if (sliceDatas == null || sliceDatas.size() < 100) { break; } realTotalSize = realTotalSize + sliceDatas.size(); } while (true); } } long endtime = System.currentTimeMillis(); System.out.println("耗时:"+(endtime - starttime)+",realTotalSize:"+realTotalSize); //查询存在es服务器上的scroll上下文信息 String scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); System.out.println(scrolls); //处理完毕后清除scroll上下文信息 if(scrollIds.size() > 0) { scrolls = clientUtil.deleteScrolls(scrollIds); System.out.println(scrolls); } //清理完毕后查看scroll上下文信息 scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); System.out.println(scrolls); }
Example 17
Source File: TestScrollQuery.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
@Test public void testScroll(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/scroll.xml"); //scroll分页检索 List<String > scrollIds = new ArrayList<>(); long starttime = System.currentTimeMillis(); Map params = new HashMap(); params.put("size", 100);//每页100条记录 ESDatas<Map> response = clientUtil.searchList("agentstat-*/_search?scroll=1m","scrollQuery",params,Map.class); List<Map> datas = response.getDatas(); long realTotalSize = datas.size(); long totalSize = response.getTotalSize(); String scrollId = response.getScrollId(); if(scrollId != null) scrollIds.add(scrollId); System.out.println("totalSize:"+totalSize); System.out.println("scrollId:"+scrollId); if(datas != null && datas.size() > 0) {//每页1000条记录,迭代scrollid,遍历scroll分页结果 do { response = clientUtil.searchScroll("1m",scrollId,Map.class); scrollId = response.getScrollId(); totalSize = response.getTotalSize(); System.out.println("scroll totalSize:"+totalSize); if(scrollId != null) scrollIds.add(scrollId); datas = response.getDatas(); if(datas == null || datas.size() == 0){ break; } realTotalSize = realTotalSize + datas.size(); } while (true); } long endtime = System.currentTimeMillis(); System.out.println("耗时:"+(endtime - starttime)+",realTotalSize:"+realTotalSize+",totalSize:"+totalSize); //查询存在es服务器上的scroll上下文信息 String scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); // System.out.println(scrolls); //处理完毕后清除scroll上下文信息 if(scrollIds.size() > 0) { scrolls = clientUtil.deleteScrolls(scrollIds); // System.out.println(scrolls); } //清理完毕后查看scroll上下文信息 scrolls = clientUtil.executeHttp("_nodes/stats/indices/search", ClientUtil.HTTP_GET); // System.out.println(scrolls); }
Example 18
Source File: BBossESStarter.java From bboss-elasticsearch with Apache License 2.0 | 2 votes |
/** * Get default elasticsearch server ConfigFile ClientInterface * @param configFile * @return */ public ClientInterface getConfigRestClient(String configFile){ return ElasticSearchHelper.getConfigRestClientUtil(configFile); }
Example 19
Source File: BBossESStarter.java From bboss-elasticsearch with Apache License 2.0 | 2 votes |
/** * Get default elasticsearch server ConfigFile ClientInterface * @param templateContainer * @return */ public ClientInterface getConfigRestClient(BaseTemplateContainerImpl templateContainer){ return ElasticSearchHelper.getConfigRestClientUtil(templateContainer); }
Example 20
Source File: BBossESStarter.java From bboss-elasticsearch with Apache License 2.0 | votes |
/** * Get Special elasticsearch server ConfigFile ClientInterface * @param elasticsearchName elasticsearch server name which defined in bboss spring boot application configfile * @param configFile * @return */ public ClientInterface getConfigRestClient(String elasticsearchName,String configFile){ return ElasticSearchHelper.getConfigRestClientUtil(elasticsearchName,configFile); }