Showing
1 changed file
with
41 additions
and
0 deletions
1 | +package com.yoho.search.restapi.tools; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import org.apache.lucene.search.join.ScoreMode; | ||
7 | +import org.elasticsearch.index.query.NestedQueryBuilder; | ||
8 | +import org.elasticsearch.index.query.QueryBuilders; | ||
9 | +import org.elasticsearch.index.query.TermsQueryBuilder; | ||
10 | +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
11 | +import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
12 | +import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
13 | +import org.springframework.stereotype.Controller; | ||
14 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
15 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
16 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
17 | + | ||
18 | +import com.alibaba.fastjson.JSON; | ||
19 | +import com.alibaba.fastjson.JSONObject; | ||
20 | +import com.yoho.search.core.es.model.SearchParam; | ||
21 | +import com.yoho.search.core.es.utils.SearchParamUtils; | ||
22 | + | ||
23 | +@Controller | ||
24 | +public class TestDslController { | ||
25 | + | ||
26 | + @RequestMapping(method = RequestMethod.GET, value = "/testDsl") | ||
27 | + @ResponseBody | ||
28 | + public JSONObject testDsl() { | ||
29 | + SearchParam searchParam = new SearchParam(); | ||
30 | + TermsQueryBuilder sknFilter = QueryBuilders.termsQuery("productSkn", "50002406"); | ||
31 | + NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("pools", QueryBuilders.termQuery("pools.pool_id", "130") ,ScoreMode.None); | ||
32 | + searchParam.setFiter(QueryBuilders.boolQuery().must(sknFilter).must(nestedQueryBuilder)); | ||
33 | + List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<AbstractAggregationBuilder<?>>(); | ||
34 | + aggregationBuilders.add(AggregationBuilders.nested("test1", "pools").subAggregation(AggregationBuilders.filter("nested_filter", QueryBuilders.termQuery("pools.pool_id", "130")).subAggregation(AggregationBuilders.terms("pool_id").field("pools.pool_id")))); | ||
35 | + searchParam.setAggregationBuilders(aggregationBuilders); | ||
36 | + SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam); | ||
37 | + | ||
38 | + return JSON.parseObject(searchSourceBuilder.toString()); | ||
39 | + } | ||
40 | + | ||
41 | +} |
-
Please register or login to post a comment