码迷,mamicode.com
首页 > 数据库 > 详细

Elasticsearch 类比 mysql 实现 in and like or

时间:2020-12-07 12:22:49      阅读:9      评论:0      收藏:0      [点我收藏+]

标签:查询方式   sele   code   tran   rgba   方式   mys   查询   elastic   

 

常用的查询方式类比mysql

       <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.6.1</version>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.6.1</version>
        </dependency>    

 

  • and
select * from user where about=‘中华人民共和国‘ and firstName=‘张’

QueryBuilders.boolQuery().must(QueryBuilders.termQuery("about","中华人民共和国")).must(QueryBuilders.termQuery("firstName","张"))
  • or
select * from user where about=‘中华人民共和国‘ and firstName=‘王’
QueryBuilders.boolQuery().should(QueryBuilders.termQuery("about","中华人民共和国")).should(QueryBuilders.termQuery("firstName","王"))
  • and or 连用
select * from user where  firstName=‘张‘ and( firstName=‘王’ or about=‘中华人民共和国公民‘)

QueryBuilders.boolQuery()
                        .must(QueryBuilders.termQuery("firstName","张"))
                        .must(QueryBuilders.boolQuery()
                                        .should(QueryBuilders.termQuery("firstName","王"))
                                        .should(QueryBuilders.termQuery("about","中华人民共和国公民"))
  • like
select * from user where about like ‘%中华%‘

QueryBuilders.wildcardQuery("about","*中华*")
  • in
select * from user where about in (‘中华人民共和国‘,‘中华人民共和国公民‘)

QueryBuilders.boolQuery()
                        .should(QueryBuilders.termQuery("about","中华人民共和国"))
                        .should(QueryBuilders.termQuery("about","中华人民共和国公民"))

 

Elasticsearch 类比 mysql 实现 in and like or

标签:查询方式   sele   code   tran   rgba   方式   mys   查询   elastic   

原文地址:https://www.cnblogs.com/luweiweicode/p/14072297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!