经纬度查询
@Test
public void geoDistanceTest() throws Exception {
SearchRequest searchRequest = new SearchRequest(EsConstant.HOTEL_INDEX);
searchRequest.source()
.query(QueryBuilders
.geoDistanceQuery("location")
.point(31.242201,121.5091060)
.distance("5", DistanceUnit.KILOMETERS));
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
printResult(response);
}
算分查询
@Test public void functionScoreTest() throws IOException { SearchRequest searchRequest = new SearchRequest(EsConstant.HOTEL_INDEX); FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder( QueryBuilders.termQuery("city", "上海"), new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{ new FunctionScoreQueryBuilder.FilterFunctionBuilder( QueryBuilders.termQuery("brand", "如家"), ScoreFunctionBuilders.weightFactorFunction(10) ) } ).boostMode(CombineFunction.MULTIPLY); searchRequest.source().query(functionScoreQueryBuilder); SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); }
match查
@Test public void matchTest() throws IOException { //创建请求对象 SearchRequest searchRequest = new SearchRequest(EsConstant.HOTEL_INDEX); //封装查询条件 searchRequest.source().query(QueryBuilders.matchQuery("all","7天")); //执行查询 SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); //解析结果 printResult(response); }