org.frameworkset.elasticsearch.client.ClientInterface Java Examples

The following examples show how to use org.frameworkset.elasticsearch.client.ClientInterface. 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 elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
public void testCreateTempate() throws ParseException{

		ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/ESTemplate.xml");
		//创建模板
		String response = clientUtil.createTempate("demotemplate_1",//模板名称
				"demoTemplate");//模板对应的脚本名称,在estrace/ESTemplate.xml中配置
		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);

	}
 
Example #2
Source File: ParentChildTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
/**
	 * 检索公司信息,并返回公司对应的雇员信息(符合检索条件的雇员信息)
	 */
	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 #3
Source File: ParentChildTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
/**
 * 通过读取配置文件中的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: ElasticSearch.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
public ClientInterface getConfigRestClientUtil(BaseTemplateContainerImpl templateContainer) {
	ClientInterface clientInterface = configClientUtis.get(templateContainer.getNamespace());
	if(clientInterface != null)
		return clientInterface;
	else {
		if (restClient != null) {
			synchronized (configClientUtis) {
				clientInterface = configClientUtis.get(templateContainer.getNamespace());
				if(clientInterface != null)
					return clientInterface;
				clientInterface = this.restClient.getConfigClientUtil(this.indexNameBuilder, templateContainer);
				configClientUtis.put(templateContainer.getNamespace(),clientInterface);
				return clientInterface;
			}
		}
		else {
			return null;
		}
	}
}
 
Example #5
Source File: SuggestionTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: TestByQuery.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: PhraseSuggestionTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: PingyinTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
	public void searchGoodParent(){
		ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/pinyin.xml");
		Map<String,String> params = new HashMap<String,String>();
//		params.put("detailName","红谷滩红角洲");
		params.put("name","xiahaotang");
		params.put("distance","2km");
		params.put("lon","115.825472");
		params.put("lat","28.665041");
		try {
			ESInnerHitSerialThreadLocal.setESInnerTypeReferences(Shop.class);
			ESSerialThreadLocal.setESTypeReferences(Good.class);
			ESDatas<SearchHit> datas = clientUtil.searchList("shop-good-user-1512023940/_search","goodParentSearch",params,SearchHit.class);
			List<SearchHit> goods = datas.getDatas();
			for(int i = 0;  i < goods.size(); i ++) {
				List<Shop> shops = ResultUtil.getInnerHits(goods.get(i).getInnerHits(), "shop", Shop.class);
			}
			System.out.print(clientUtil.executeRequest("shop-good-user-1512023940/_search?pretty", "goodParentSearch", params));
		}
		finally {
			ESInnerHitSerialThreadLocal.clean();
			ESSerialThreadLocal.clean();
		}
	}
 
Example #9
Source File: PingyinTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
public void importShopGood() throws IOException {

	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	String data = FileUtil.getFileContent("F:\\4_ASIA文档\\1_项目\\13_江西移动\\拼音搜索\\数据\\shops","UTF-8");
	long time = System.currentTimeMillis();

	String temp = clientUtil.executeHttp("_bulk",data, ClientUtil.HTTP_POST);
	System.out.println(temp);
	System.out.println("耗时:"+(System.currentTimeMillis() - time)+"毫秒");

	data = FileUtil.getFileContent("F:\\4_ASIA文档\\1_项目\\13_江西移动\\拼音搜索\\数据\\good","UTF-8");
	time = System.currentTimeMillis();

	temp = clientUtil.executeHttp("_bulk",data, ClientUtil.HTTP_POST);
	System.out.println(temp);
	System.out.println("耗时:"+(System.currentTimeMillis() - time)+"毫秒");

	data = FileUtil.getFileContent("F:\\4_ASIA文档\\1_项目\\13_江西移动\\拼音搜索\\数据\\orders","UTF-8");
	time = System.currentTimeMillis();

	temp = clientUtil.executeHttp("_bulk",data, ClientUtil.HTTP_POST);
	System.out.println(temp);
	System.out.println("耗时:"+(System.currentTimeMillis() - time)+"毫秒");
}
 
Example #10
Source File: TestUpdate.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
public void testPartitionUpdateWithDSL(){
	ClientInterface configRestClientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/agentstat.xml");
	Map params = new HashMap();
	Date date = new Date();
	params.put("eventTimestamp",date.getTime());
	params.put("eventTimestampDate",date);
	/**
	 * 采用dsl更新索引部分内容,dsl定义和路径api可以参考文档:
	 * https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
	 */
	StringBuilder path = new StringBuilder();
	path.append("agentinfo/agentinfo/pdpagent/_update?refresh");//自行拼接rest api地址
	configRestClientUtil.updateByPath(path.toString(),
									"updateAgentInfoEndtime",//更新文档内容的dsl配置名称
			                         params);
}
 
Example #11
Source File: ESTest.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: TestMGet.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
public void testMgetWithDSL(){
	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/mget.xml");
	//通过执行dsl获取多个文档的内容
	List<String> ids = new ArrayList<String>();
	ids.add("10.21.20.168");
	ids.add("192.168.0.143");
	Map params = new HashMap();
	params.put("ids",ids);
	String response = clientUtil.executeHttp("_mget",
											 "testMget",//dsl定义名称
											 params, //存放文档id的参数
			                                 ClientUtil.HTTP_POST);
	System.out.println(response);
	List<Map> docs = clientUtil.mgetDocuments("_mget",
											"testMget",//dsl定义名称
											 params, //存放文档id的参数
											 Map.class);//返回文档对象类型
	System.out.println(docs);
}
 
Example #13
Source File: ESTest.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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 #14
Source File: ESTest.java    From bboss-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTempate() throws ParseException{

	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTemplate.xml");
	//创建模板
	String response = clientUtil.createTempate("demotemplate_1",//模板名称
			"demoTemplate");//模板对应的脚本名称,在estrace/ESTemplate.xml中配置
	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);

}
 
Example #15
Source File: PingyinTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
	public void testCreateDemoMapping(){

		ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/pinyin.xml");
		try {
			//可以先删除索引mapping,重新初始化数据
			clientUtil.dropIndice("demo");
		} catch (ElasticSearchException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


//
		//创建索引表结构
		String response = clientUtil.createIndiceMapping("demo","createDemoIndice");
//       获取并打印创建的索引表结构
		System.out.println(clientUtil.getIndice("demo"));

	}
 
Example #16
Source File: PingyinTest.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
public void updateDocument(){
	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/pinyin.xml");

	Map<String,String> params = new HashMap<String,String>();
	params.put("cityName","潭市");
	params.put("standardAddrId","38130122");
	params.put("detailName","tan市贵溪市花园办事处建设路四冶生活区2-11栋3单元1层101");
	params.put("location","28.292781,117.238963");
	params.put("countyName","贵溪市");

	String temp = clientUtil.executeHttp("pboos-map-adress-1503973107/boosmap/38130122/_update",
			"updateDocument",
			params,
			ClientInterface.HTTP_POST);
	System.out.println(temp);

}
 
Example #17
Source File: TestUpdate.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
@Test
public void testPartitionUpdate(){
	Map params = new HashMap();
	Date date = new Date();
	params.put("eventTimestamp",date.getTime());
	params.put("eventTimestampDate",date);
	/**
	 * 更新索引部分内容
	 */
	ClientInterface restClientUtil = ElasticSearchHelper.getRestClientUtil();
	String response = restClientUtil.updateDocument("agentinfo",//索引表名称
													"agentinfo",//索引type
													"pdpagent",//索引id
													 params,//待更新的索引字段信息
													"refresh");//强制刷新索引
	System.out.println(response);
}
 
Example #18
Source File: UpdateSetting.java    From elasticsearch-gradle-example with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args){
	ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil();
	int max_result_window = CommonLauncher.getIntProperty("max_result_window",15000);
	Map<String,Object> settings = new HashMap<String,Object>();
	settings.put("index.max_result_window",max_result_window);
	String result = clientInterface.updateAllIndicesSettings(settings);//修改所有索引的max_result_window设置

	System.out.println(result);

	result = clientInterface.updateIndiceSettings("dbdemo",settings) ;//修改索引dbdemo的max_result_window设置
	System.out.println(result);
	String setting = clientInterface.getClusterSettings();
	System.out.println(setting);


}
 
Example #19
Source File: ParentChildTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
/**
 * 通过雇员姓名检索公司信息
 */
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 #20
Source File: ESTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
public void testAddDateDocument() throws ParseException{
	testGetmapping();
	SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
	String date = format.format(new Date());
	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/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",//索引类型
			"createDemoDocument",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			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",//索引类型
			"5",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			Demo.class);
}
 
Example #21
Source File: PingyinTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@Test
	public void searchPinyinShopMatch_phrase_prefix(){
		ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/pinyin.xml");
		Map<String,String> params = new HashMap<String,String>();
//		params.put("detailName","红谷滩红角洲");
		params.put("name","xia壕塘15");
//		params.put("name","下壕塘15");
		params.put("distance","2km");
		params.put("lon","115.825472");
		params.put("lat","28.665041");
		ESDatas<Shop> datas = clientUtil.searchList("shop-good-user-1512023940/_search","searchShopGoodUser",params,Shop.class);
		System.out.print(clientUtil.executeRequest("shop-good-user-1512023940/_search?pretty","searchShopGoodUser",params));
	}
 
Example #22
Source File: TestDocumentGet.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDocSource(){
	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	//获取json报文索引source,不返回索引元数据
	String response = clientUtil.getDocumentSource("agentinfo/agentinfo/10.21.20.168/_source");
	System.out.println(response);
	//获取对象类型source,此处对象类型是map,可以指定自定义的对象类型,不返回索引元数据
	Map data = clientUtil.getDocumentSource("agentinfo/agentinfo/10.21.20.168/_source",Map.class);
	System.out.println(data);
	//请求地址格式说明:
	// index/indexType/docId/_source
	// 实例如下:
	// "agentinfo/agentinfo/10.21.20.168/_source"

}
 
Example #23
Source File: TestDocumentGet.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDoc(){
	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	String response = clientUtil.getDocumentByPath("agentinfo/agentinfo/10.21.20.168");
	System.out.println(response);
	Map data = clientUtil.getDocumentByPath("agentinfo/agentinfo/10.21.20.168",Map.class);
	System.out.println(data);
	//请求地址格式说明:
	// index/indexType/docId
	// 实例如下:
	// "agentinfo/agentinfo/10.21.20.168"
}
 
Example #24
Source File: TraceESDaoTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDocument(){
	String id = "AV9hXgBkioW8Iiove8hI";
	String indexName = "trace-2017.10.28";
	String indexType = "trace";
	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	MapSearchHit hit = clientUtil.getDocumentHit(indexName,indexType,id);
	System.out.println("");
}
 
Example #25
Source File: ESTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
public void testAddDocument() throws ParseException{
	testGetmapping();

	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/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.addDocument("demo",//索引表,自动添加日期信息到索引表名称中
			"demo",//索引类型
			"createDemoDocument",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			demo);

	System.out.println("addDateDocument-------------------------");
	System.out.println(response);

	response = clientUtil.getDocument("demo",//索引表
			"demo",//索引类型
			"5");
	System.out.println("getDocument-------------------------");
	System.out.println(response);

	demo = clientUtil.getDocument("demo",//索引表
			"demo",//索引类型
			"5",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			Demo.class);
}
 
Example #26
Source File: ESTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
public void testBulkAddDateDocument() throws ParseException{
	testGetmapping();
	SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
	String date = format.format(new Date());
	ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/estrace/ESTracesMapper.xml");
	List<Demo> demos = new ArrayList<>();
	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",//索引类型
			"createDemoDocument",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			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",//索引类型
			"3",//创建文档对应的脚本名称,在esmapper/estrace/ESTracesMapper.xml中配置
			Demo.class);
}
 
Example #27
Source File: TraceESDaoTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@Test
public void clusterState(){
	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	//返回json格式集群状态
	String state = clientUtil.executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET);
	System.out.println(state);

}
 
Example #28
Source File: BBossESStarter.java    From bboss-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Get default elasticsearch server ClientInterface
 * @return
 */
public ClientInterface getRestClient(){
	if(restClient == null) {
		synchronized (this) {
			if(restClient == null) {
				restClient = ElasticSearchHelper.getRestClientUtil();
			}
		}
	}
	return restClient;
}
 
Example #29
Source File: ESTest.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
public void testGetmapping(){
	SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
	String date = format.format(new Date());
	ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
	System.out.println(clientUtil.getIndice("demo-"+date));
	clientUtil.dropIndice("demo-"+date);
}
 
Example #30
Source File: TestBulk.java    From elasticsearch-gradle-example with Apache License 2.0 5 votes vote down vote up
@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);

}