我有以下弹性搜索查询
SearchResponse response = DbContext.INSTANCE.client()
.prepareSearch(indexList)
.setTypes("docs")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(queryBuilder)
.setFilter(FilterBuilders.andFilter(f1, f2))
.addFacet(FacetBuilders.termsFacet("f").field("frm").size(10))
.setFrom(pageNumber).setSize(size).execute().actionGet();
此查询返回的方面计数是全局的,如何获取搜索响应的方面?
我找到了答案:我所做的是在主查询中添加过滤器
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.queryString(criterion.getFullText()).field("text"))
.must(QueryBuilders.termsQuery("from", criterion.getFrom().toArray((new String[0]))))
.must(QueryBuilders.termsQuery("to", criterion.getTo().toArray((new String[0]))))
.must(QueryBuilders.rangeQuery("date").from(dtf.print(criterion.getFromDate())).to(dtf.print(criterion.getToDate())));
SearchResponse response =
DbContext.INSTANCE.client()
.prepareSearch(indexList)
.setTypes("docs")
.setQuery(queryBuilder)
.addFacet(fb)
.addFacet(tf)
.addSort("date", SortOrder.DESC)
.setFrom(pageNumber).setSize(size).execute().actionGet();