范围查询的DSL语句:{"query":{"range":{"sendtime":{"from":"2019-01-01 00:00:00","to":"2019-12-31 23:59:59","include_lower":true,"include_upper":true,"boost":1.0}}}}
范围查询的String结果:{"uid":12345,"phone":123456789019,"msgcode":2,"sendtime":"2019-03-14 01:57:04","message":"xuwujing study Elasticsearch"}
范围查询的String结果:{"uid":"123456","phone":"12345678909","message":"xu1","sendtime":"2019-03-14 01:57:04"}
范围查询的String结果:{"uid":"12345","phone":"12345678909","message":"qq","msgcode":"1","sendtime":"2019-03-14 01:57:04"}
=================
正则查询的DSL语句:{"query":{"regexp":{"message":{"value":"xu[0-9]","flags_value":65535,"max_determinized_states":10000,"boost":1.0}}}}
正则查询的Map结果:{uid=123456, phone=12345678909, message=xu1, sendtime=2019-03-14 01:57:04}
正则查询的String结果:{"uid":"123456","phone":"12345678909","message":"xu1","sendtime":"2019-03-14 01:57:04"}
=================
组合查询的DSL语句:{"query":{"bool":{"must":[{"term":{"uid":{"value":12345,"boost":1.0}}},{"term":{"msgcode":{"value":1,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}}
组合查询的String结果:{"uid":"12345","phone":"12345678909","message":"qq","msgcode":"1","sendtime":"2019-03-14 01:57:04"}
=================
其它参考ES官方文档:
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
关于SpringBoot集成ElasticSearch和JestClient的使用可以查看这篇文章:SpringBoot整合ElasticSearch实现多版本的兼容
关于ElasticSearch Java API的选择,如果ElasticSearch版本在6.x以前的话,推荐使用JestClient。如果是6.x之后并且有意升级到7.x的话,那么直接使用ES官方的Java High Level REST Client,因为在7.x之后将直接会舍弃Transport client的连接方式,目前Spring和SpringBoot集成的ES就是使用该方式(不知后续是否会做调整)。
本篇文章的代码已收录在本人的java-study项目中,若有兴趣,欢迎star、fork和issues。
项目地址:https://github.com/xuwujing/java-study
ElasticSearch实战系列:
ElasticSearch实战系列一: ElasticSearch集群+Kinaba安装教程
ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解
原创不易,如果感觉不错,希望给个推荐!您的支持是我写作的最大动力!
版权声明:
作者:虚无境
博客园出处:
CSDN出处:
个人博客出处: