代码拉取完成,页面将自动刷新
这个demo集成了ESClientRHL,是个简单的springboot工程,只要拥有一个es服务和本demo就可以完成客户端与es的交互
单测目录中还包含各种esclientRHL的高级功能使用示例
本地部署一个es服务,端口默认9200,即访问http://localhost:9200可以访问
可以下载本例中的es版本7.3.1
<properties>
<java.version>1.8</java.version>
<elasticsearch.version>7.3.1</elasticsearch.version>
</properties>
<dependency>
<groupId>cn.zxporz</groupId>
<artifactId>esclientrhl</artifactId>
<version>7.0.2</version>
</dependency>
EnableESTools
@SpringBootApplication
@EnableESTools(basePackages={"org.zxp.esclientrhl.demo.repository"},entityPath = {"org.zxp.esclientrhl.demo.domain"})
public class EsclientrhlDemoApplication
application.properties
server.port=8888
elasticsearch.host=127.0.0.1:9200
@ESMetaData(indexName = "index_demo",number_of_shards = 3,number_of_replicas = 0,printLog = true)
public class IndexDemo {
@ESID
private String proposal_no;
@ESMapping(datatype = DataType.keyword_type)
private String risk_code;
@ESMapping(datatype = DataType.text_type)
private String risk_name;
@ESMapping(keyword = true)
private String business_nature;
@ESMapping(datatype = DataType.text_type)
private String business_nature_name;
private String appli_code;//可以用默认值,这样会有appli_code.keyword可以直接搜
@ESMapping(suggest = true)
private String appli_name;
private String insured_code;
@ESMapping(ngram = true)
private String insured_name;
@ESMapping(datatype = DataType.date_type)
private Date operate_date;
@ESMapping(datatype = DataType.text_type)
private String operate_date_format;
@ESMapping(datatype = DataType.date_type)
private Date start_date;
@ESMapping(datatype = DataType.date_type)
private Date end_date;
@ESMapping(datatype = DataType.double_type)
private double sum_amount;
@ESMapping(datatype = DataType.double_type)
private double sum_premium;
@ESMapping(datatype = DataType.keyword_type)
private String com_code;
……
public interface IndexDemoRepository extends ESCRepository<IndexDemo,String> {
}
@RestController
public class IndexDemoController {
@Autowired
private IndexDemoRepository indexDemoRepository;
//http://127.0.0.1:8888/demo/add
@GetMapping("/demo/add")
public String add() throws Exception {
IndexDemo indexDemo = new IndexDemo();
indexDemo.setProposal_no("1");
indexDemo.setAppli_name("a1");
indexDemo.setRisk_code("aa1");
indexDemo.setSum_premium(1);
indexDemoRepository.save(indexDemo);
return "新增成功";
}
//http://127.0.0.1:8888/demo/add_list
@GetMapping("/demo/add_list")
public String addList() throws Exception {
IndexDemo indexDemo2 = new IndexDemo();
indexDemo2.setProposal_no("2");
indexDemo2.setAppli_name("a2");
indexDemo2.setRisk_code("aa2");
indexDemo2.setSum_premium(2);
IndexDemo indexDemo3 = new IndexDemo();
indexDemo3.setProposal_no("3");
indexDemo3.setAppli_name("a3");
indexDemo3.setRisk_code("aa3");
indexDemo3.setSum_premium(3);
indexDemoRepository.save(Arrays.asList(indexDemo2,indexDemo3));
return "新增成功";
}
//http://127.0.0.1:8888/demo/update
@GetMapping("/demo/update")
public String update() throws Exception {
IndexDemo indexDemo = new IndexDemo();
indexDemo.setProposal_no("1");
indexDemo.setAppli_name("a999999");
indexDemo.setRisk_code("aa9999999");
indexDemo.setSum_premium(99999);
indexDemoRepository.update(indexDemo);
return "修改成功";
}
//http://127.0.0.1:8888/demo/delete
@GetMapping("/demo/delete")
public String delete() throws Exception {
IndexDemo indexDemo = new IndexDemo();
indexDemo.setProposal_no("1");
indexDemo.setAppli_name("a999999");
indexDemo.setRisk_code("a9999999");
indexDemo.setSum_premium(99999);
indexDemoRepository.delete(indexDemo);
return "删除成功";
}
//http://127.0.0.1:8888/demo/query
@GetMapping("/demo/query")
public List<IndexDemo> query() throws Exception {
List<IndexDemo> search = indexDemoRepository.search(QueryBuilders.matchAllQuery());
return search;
}
}
test
包下代码此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。