您现在的位置是:首页 > 文章详情
ElasticSearch From-Size分页案例
日期:2018-06-13点击:376收藏
ElasticSearch From-Size分页案例
1.定义from-size检索的dsl
定义from-size检索的dsl,里面包含外部需要传入的检索条件参数变量和分页参数变量:
2.加载dsl所在配置文件,并执行from-size分页检索
3.完整的demo实例工程
https://github.com/bbossgroups/eshelloword-booter
https://gitee.com/bbossgroups/eshelloword-booter
4 开发交流
elasticsearch技术交流群:166471282
elasticsearch微信公众号:
1.定义from-size检索的dsl
定义from-size检索的dsl,里面包含外部需要传入的检索条件参数变量和分页参数变量:
<!-- 一个简单的检索dsl,中有四个变量 applicationName1 applicationName2 startTime endTime 通过map传递变量参数值 变量语法参考文档: --> <property name="searchPagineDatas"> <![CDATA[{ "query": { "bool": { "filter": [ { ## 多值检索,查找多个应用名称对应的文档记录 "terms": { "applicationName.keyword": [#[applicationName1],#[applicationName2]] } }, { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 "range": { "agentStarttime": { "gte": #[startTime],##统计开始时间 "lt": #[endTime] ##统计截止时间 } } } ] } }, ## 分页起点 "from":#[from], ## 最多返回size条记录 "size":#[size] }]]> </property>
2.加载dsl所在配置文件,并执行from-size分页检索
/** * 分页检索文档 * @throws ParseException */ public void testPagineSearch() throws ParseException { //创建加载配置文件的客户端工具,用来检索文档,单实例多线程安全 ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/demo.xml"); //设定查询条件,通过map传递变量参数值,key对于dsl中的变量名称 //dsl中有四个变量 // applicationName1 // applicationName2 // startTime // endTime Map<String,Object> params = new HashMap<String,Object>(); //设置applicationName1和applicationName2两个变量的值 params.put("applicationName1","blackcatdemo2"); params.put("applicationName2","blackcatdemo3"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间范围,时间参数接受long值 params.put("startTime",dateFormat.parse("2017-09-02 00:00:00")); params.put("endTime",new Date()); ESDatas<Demo> esDatas = null;//返回的文档封装对象类型 //保存总记录数 long totalSize = 0; //保存每页结果对象列表,最多返回1000条记录 List<Demo> demos = null; int i = 0; //页码 do{//遍历获取每页的记录 //设置分页参数 params.put("from",i * 1000);//分页起点 params.put("size",1000);//每页返回1000条 i ++;//往前加页码 //执行查询,demo为索引表,_search为检索操作action esDatas = //ESDatas包含当前检索的记录集合,最多1000条记录,由dsl中的size属性指定 clientUtil.searchList("demo/_search",//demo为索引表,_search为检索操作action "searchPagineDatas",//esmapper/demo.xml中定义的dsl语句 params,//变量参数 Demo.class);//返回的文档封装对象类型 demos = esDatas.getDatas();//每页结果对象列表,最多返回1000条记录 totalSize = esDatas.getTotalSize();//总记录数 if(i * 1000 > totalSize) break; }while(true); // String json = clientUtil.executeRequest("demo/_search",//demo为索引表,_search为检索操作action // "searchDatas",//esmapper/demo.xml中定义的dsl语句 // params); // String json = com.frameworkset.util.SimpleStringUtil.object2json(demos); System.out.println(totalSize); }
3.完整的demo实例工程
https://github.com/bbossgroups/eshelloword-booter
https://gitee.com/bbossgroups/eshelloword-booter
4 开发交流
elasticsearch技术交流群:166471282
elasticsearch微信公众号:
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
centos6安装ElasticSearch5.6.5错误记录
在centos6安装ES的时候遇到不少问题。这里记录日志。以后安装一定要升级centos7,别说啥稳定问题了,该升级就升级。 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max number of threads [1024] for user [es] is too low, increase to at least [2048] [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk 解决方案: vim config/e...
- 下一篇
HBase + SpringBoot分布式文件存储实战(一)-简介
技术分析前提
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
扫描即可查看该文章
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Hadoop3单机部署,实现最简伪集群
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果