- 89_熟练掌握ES Java API_对汽车品牌进行多种条件的组
- 88_熟练掌握ES Java API_对汽车品牌进行全文检索、精
- 90_熟练掌握ES Java API_基于地理位置对周围汽车4S
- 87_熟练掌握ES Java API_基于search temp
- 83_熟练掌握ES Java API_基于upsert实现汽车最
- 86_熟练掌握ES Java API_基于scroll实现月度销
- 85_熟练掌握ES Java API_基于bulk实现多4S店销
- 84_熟练掌握ES Java API_基于mget实现多辆汽车的
- es(2)—复杂的多条件查询(bool查询与constant_s
- Springboot2.x 两种方式操作增删改查Elastics
89_熟练掌握ES Java API_对汽车品牌进行多种条件的组合搜索
多种搜索结合一起搜索---must--mustnot--should--filter
QueryBuilder qb = boolQuery()
.must(matchQuery("brand", "宝马"))
.mustNot(termQuery("name.raw", "宝马318"))
.should(termQuery("produce_date", "2017-01-02"))
.filter(rangeQuery("price").gte("280000").lt("350000"));
SearchResponse response = client.prepareSearch("car_shop")
.setTypes("cars")
.setQuery(qb)
.get();
源代码 BoolQuerySearchBrand
public class BoolQuerySearchBrand {
@SuppressWarnings({ "resource", "unchecked" })
public static void main(String[] args) throws Exception {
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch")
.build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("brand", "宝马"))
.mustNot(QueryBuilders.termQuery("name.raw", "宝马318"))
.should(QueryBuilders.rangeQuery("produce_date").gte("2017-01-01").lte("2017-01-31"))
.filter(QueryBuilders.rangeQuery("price").gte(280000).lte(350000));
SearchResponse searchResponse = client.prepareSearch("car_shop")
.setTypes("cars")
.setQuery(queryBuilder)
.get();
for(SearchHit searchHit : searchResponse.getHits().getHits()) {
System.out.println(searchHit.getSourceAsString());
}
client.close();
}
}
网友评论