org.frameworkset.elasticsearch.ElasticSearchHelper Java Examples
The following examples show how to use
org.frameworkset.elasticsearch.ElasticSearchHelper.
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 hasParentSearchByCountryReturnParent2ndChildren(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("country","UK"); try { ESInnerHitSerialThreadLocal.setESInnerTypeReferences(Company.class);//指定inner查询结果对于公司类型,公司只有一个文档类型,索引不需要显示指定company类型信息 ESDatas<Employee> escompanys = clientUtil.searchList("company/employee/_search", "hasParentSearchByCountryReturnParent2ndChildren",params,Employee.class); List<Employee> employeeList = escompanys.getDatas();//获取符合条件的雇员数据 long totalSize = escompanys.getTotalSize(); //查看每个雇员对应的公司信息 for(int i = 0; i < employeeList.size(); i ++) { Employee employee = employeeList.get(i); List<Company> companies = ResultUtil.getInnerHits(employee.getInnerHits(), "company"); System.out.println(companies.size()); } } finally{ ESInnerHitSerialThreadLocal.clean();//清空inner查询结果对于公司类型 } }
Example #2
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 #3
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 6 votes |
/** * 通过读取配置文件中的dsl json数据导入雇员和公司数据 */ public void importClientInfoFromJsonData(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/Client_Info.xml"); clientUtil.executeHttp("client_info/basic/_bulk?refresh","bulkImportBasicData",ClientUtil.HTTP_POST); clientUtil.executeHttp("client_info/diagnosis/_bulk?refresh","bulkImportDiagnosisData",ClientUtil.HTTP_POST); clientUtil.executeHttp("client_info/medical/_bulk?refresh","bulkImportMedicalData",ClientUtil.HTTP_POST); clientUtil.executeHttp("client_info/exam/_bulk?refresh","bulkImportExamData",ClientUtil.HTTP_POST); long companycount = clientUtil.countAll("client_info/basic"); System.out.println(companycount); long basiccount = clientUtil.countAll("client_info/basic"); System.out.println(basiccount); long medicalcount = clientUtil.countAll("client_info/medical"); System.out.println(medicalcount); long examcount = clientUtil.countAll("client_info/exam"); System.out.println(examcount); long diagnosiscount = clientUtil.countAll("client_info/diagnosis"); System.out.println(diagnosiscount); }
Example #4
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 #5
Source File: ElasticSearchConfigBoot.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
public static void boot(Map properties,boolean fromspringboot){ synchronized (ElasticSearchConfigBoot.class) { final PropertiesContainer propertiesContainer = new PropertiesContainer(); propertiesContainer.addAll(properties); String _elasticsearchServerNames = propertiesContainer.getExternalProperty("elasticsearch.serverNames", "default"); String[] elasticsearchServerNames = _elasticsearchServerNames.split(","); //初始化Http连接池 GetProperties getProperties = new WrapperGetProperties(propertiesContainer); ClientConfiguration.bootClientConfiguations(elasticsearchServerNames, getProperties); ClientConfiguration.bootHealthCheckClientConfiguations(elasticsearchServerNames, getProperties); //初始化ElasticSearchServer ElasticSearchHelper.booter(elasticsearchServerNames, propertiesContainer,true,fromspringboot); } }
Example #6
Source File: WrapperGetProperties.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
/** * 如果没有配置http连接池账号和口令,则将es账号和口令转为http协议账号和口令 * @param namespace * @param property * @return */ @Override public String getExternalPropertyWithNS(String namespace, String property) { String value = null; if(property.endsWith(ClientConfiguration.http_authAccount)) { value = context.getExternalProperty(property); if(SimpleStringUtil.isEmpty(value)){ value = ElasticSearchHelper._getStringValue(namespace,"elasticUser",context,null); } } else if(property.endsWith(ClientConfiguration.http_authPassword)) { value = context.getExternalProperty(property); if(SimpleStringUtil.isEmpty(value)){ value = ElasticSearchHelper._getStringValue(namespace,"elasticPassword",context,null); } } else{ value = context.getExternalProperty(property); } return value; }
Example #7
Source File: BulkProcessor.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
public void init(){ if(inited) return; this.inited = true; clientInterface = ElasticSearchHelper.getRestClientUtil(bulkConfig.getElasticsearch()); this.bulkCommand = buildBulkCommand(); executor = ThreadPoolFactory.buildThreadPool(bulkConfig.getBulkProcessorName(),bulkConfig.getBulkRejectMessage(), this.bulkConfig.getWorkThreads(),this.bulkConfig.getWorkThreadQueue(), this.bulkConfig.getBlockedWaitTimeout() ,this.bulkConfig.getWarnMultsRejects()); // dataQueue = new ArrayBlockingQueue<BulkData>(bulkConfig.getBulkQueue()); if(bulkConfig.getFlushInterval() > 0) { flush = new Thread(new Flush(), bulkConfig.getBulkProcessorName() + "-flush-thread"); flush.start(); } BaseApplicationContext.addShutdownHook(new Runnable() { @Override public void run() { shutDown(); } }); }
Example #8
Source File: ESUtil.java From bboss-elasticsearch with Apache License 2.0 | 6 votes |
private void checkESUtil(){ refresh_interval = ElasticSearchHelper.getDslfileRefreshInterval(); if(refresh_interval > 0) { if(damon == null) { synchronized(lock) { if(damon == null) { damon = new DaemonThread(refresh_interval,"ElasticSearch DSL Template Refresh Worker"); damon.start(); } } } templatecontext.monitor(damon,new ResourceTempateRefresh(this)); // damon.addFile(fileUrl,templateNamespace, new ResourceTempateRefresh(sqlutil)); } else{ log.debug("ElasticSearch DSL Template Refresh Interval:"+refresh_interval+",ignore hotload DSL Template["+templatecontext.getNamespace()+"]"); } }
Example #9
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 #10
Source File: PhraseSuggestionTest.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("test"); String template = clientUtil.createIndiceMapping("test","createPhraseTestIndice"); System.out.println(template); template = clientUtil.getIndexMapping("test"); System.out.println(template); } catch (ElasticSearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #11
Source File: TestBulk.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
@Test public void testBulkUpdate(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/bulk.xml"); List<OnlineGoodsInfoUpdateParams> onlineGoodsInfoUpdateParamss = new ArrayList<>(); OnlineGoodsInfoUpdateParams onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType("aaa"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType("aaa"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); Map<String,Object> params = new HashMap<>(); params.put("onlineGoodsInfoUpdateParamss",onlineGoodsInfoUpdateParamss); String response = clientUtil.executeHttp("_bulk", "updateOnlineGoodsesInfo", params, ClientUtil.HTTP_POST); System.out.println(response); }
Example #12
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 #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: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过读取配置文件中的dsl json数据导入雇员和公司数据 */ public void importFromJsonData(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); //导入公司数据,并且实时刷新,测试需要,实际环境不要带refresh clientUtil.executeHttp("company/company/_bulk?refresh","bulkImportCompanyData",ClientUtil.HTTP_POST); //导入雇员数据,并且实时刷新,测试需要,实际环境不要带refresh clientUtil.executeHttp("company/employee/_bulk?refresh","bulkImportEmployeeData",ClientUtil.HTTP_POST); long companycount = clientUtil.countAll("company/company"); System.out.println(companycount); long employeecount = clientUtil.countAll("company/employee"); System.out.println(employeecount); }
Example #15
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过List集合导入雇员和公司数据 */ public void importDataFromBeans() { ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); //导入公司数据,并且实时刷新,测试需要,实际环境不要带refresh List<Company> companies = buildCompanies(); clientUtil.addDocuments("company","company",companies,"refresh"); //导入雇员数据,并且实时刷新,测试需要,实际环境不要带refresh List<Employee> employees = buildEmployees(); clientUtil.addDocuments("company","employee",employees,"refresh"); }
Example #16
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 #17
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 #18
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过雇员数量检索公司信息 */ public void hasChildSearchByMinChild(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("min_children",2); ESDatas<Company> escompanys = clientUtil.searchList("company/company/_search","hasChildSearchByMinChild",params,Company.class); List<Company> companyList = escompanys.getDatas();//获取符合条件的公司 long totalSize = escompanys.getTotalSize(); }
Example #19
Source File: ParentChildTest.java From elasticsearch-gradle-example with Apache License 2.0 | 5 votes |
/** * 通过公司所在国家检索雇员信息 */ public void hasParentSearchByCountry(){ ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/indexparentchild.xml"); Map<String,Object> params = new HashMap<String,Object>(); params.put("country","UK"); ESDatas<Employee> escompanys = clientUtil.searchList("company/employee/_search","hasParentSearchByCountry",params,Employee.class); List<Employee> companyList = escompanys.getDatas();//获取符合条件的公司 long totalSize = escompanys.getTotalSize(); }
Example #20
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 #21
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 #22
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 #23
Source File: BBossESStarter.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
/** * Get default elasticsearch server ClientInterface * @return */ public ClientInterface getRestClient(){ if(restClient == null) { synchronized (this) { if(restClient == null) { restClient = ElasticSearchHelper.getRestClientUtil(); } } } return restClient; }
Example #24
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 #25
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 #26
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 #27
Source File: WrapperGetProperties.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
/** * 如果没有配置http连接池账号和口令,则将es账号和口令转为http协议账号和口令 * @param namespace * @param property * @param defaultValue * @return */ @Override public String getExternalPropertyWithNS(String namespace, String property, String defaultValue) { String value = null; if(property.endsWith(ClientConfiguration.http_authAccount)) { value = context.getExternalProperty(property); if(SimpleStringUtil.isEmpty(value)){ value = ElasticSearchHelper._getStringValue(namespace,"elasticUser",context,null); } } else if(property.endsWith(ClientConfiguration.http_authPassword)) { value = context.getExternalProperty(property); if(SimpleStringUtil.isEmpty(value)){ value = ElasticSearchHelper._getStringValue(namespace,"elasticPassword",context,null); } } else{ value = context.getExternalProperty(property); } if(value != null) return value; else return defaultValue; }
Example #28
Source File: ElasticSearchConfigBoot.java From bboss-elasticsearch with Apache License 2.0 | 5 votes |
/** * * @param forceBoot 强制启动 */ public static void boot(boolean forceBoot){ if(inited) { if(!forceBoot) return; } synchronized (ElasticSearchConfigBoot.class) { if(inited){ if(!forceBoot) return; } try { final BaseApplicationContext context = DefaultApplicationContext.getApplicationContext("conf/elasticsearch-boot-config.xml",forceBoot); String _elasticsearchServerNames = context.getExternalProperty("elasticsearch.serverNames", "default"); String[] elasticsearchServerNames = _elasticsearchServerNames.split(","); //初始化Http连接池 GetProperties getProperties = new WrapperGetProperties(context); ClientConfiguration.bootClientConfiguations(elasticsearchServerNames, getProperties ); ClientConfiguration.bootHealthCheckClientConfiguations(elasticsearchServerNames,getProperties); //初始化ElasticSearchServer ElasticSearchHelper.booter(elasticsearchServerNames, context,forceBoot,false); } finally { inited = true; } } }
Example #29
Source File: TestBulk.java From elasticsearch-gradle-example with Apache License 2.0 | 4 votes |
@Test public void testOrmBulk(){ ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); List<OnlineGoodsInfoUpdateParams> onlineGoodsInfoUpdateParamss = new ArrayList<>(); OnlineGoodsInfoUpdateParams onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setParentId("ppaa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); onlineGoodsInfoUpdateParams.setDocAsUpsert(true); onlineGoodsInfoUpdateParams.setRetryOnConflict(3); onlineGoodsInfoUpdateParams.setReturnSource(true); onlineGoodsInfoUpdateParams.setRouting("test"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType(ClientInterface.VERSION_TYPE_INTERNAL); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); onlineGoodsInfoUpdateParams = new OnlineGoodsInfoUpdateParams(); onlineGoodsInfoUpdateParams.setId("aa"); onlineGoodsInfoUpdateParams.setParentId("ppaa"); onlineGoodsInfoUpdateParams.setType("tt"); onlineGoodsInfoUpdateParams.setIndex("ddd"); onlineGoodsInfoUpdateParams.setGoodsName("dddd"); /** * 设置更新文档控制变量 */ onlineGoodsInfoUpdateParams.setDocAsUpsert(true); onlineGoodsInfoUpdateParams.setRetryOnConflict(3); onlineGoodsInfoUpdateParams.setReturnSource(true); onlineGoodsInfoUpdateParams.setRouting("test"); onlineGoodsInfoUpdateParams.setVersion(1); onlineGoodsInfoUpdateParams.setVersionType(ClientInterface.VERSION_TYPE_INTERNAL); onlineGoodsInfoUpdateParamss.add(onlineGoodsInfoUpdateParams); System.out.println(clientUtil.getDynamicIndexName("test")); String response = clientUtil.updateDocuments("aa","tt",onlineGoodsInfoUpdateParamss); System.out.println(response); }
Example #30
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); }