-1

我有以下弹性搜索查询

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();
4

1 回答 1

1

这就是我所做的,除非您想要“主要”搜索并且构面具有不同的搜索要求。 global=false应该为你解决问题

"facets": {
  "volume_by_day": {
    "date_histogram": {
      "field": "crdate",
      "interval": "day"
    },
    "global": "false"
  }
}
于 2014-03-13T11:39:25.590 回答