聚合时,设置的查询条件没有起作用
searchRequestBuilder.setTypes(ESTransportClient.getIndexType());
// 设置查询类型 1.SearchType.DFS_QUERY_THEN_FETCH = 精确查询 2.SearchType.SCAN
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
// 设置查询关键词
QueryBuilder matchQuery = QueryBuilders.multiMatchQuery(keyword, "content", "title", "summary")
.type(Type.MOST_FIELDS);
searchRequestBuilder.setQuery(matchQuery);
//searchRequestBuilder.setQuery(QueryBuilders.termQuery("searchType", SearchTypeConstant.SOFTWARE));
searchRequestBuilder.setSize(0);
// QueryBuilders.t
searchRequestBuilder.setPostFilter(QueryBuilders.termQuery("searchType", SearchTypeConstant.SOFTWARE));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("category_count").field("categoryId"));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("product_count").field("productId"));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("attr_count").field("attr"));
SearchResponse response = searchRequestBuilder.execute().actionGet();
searchRequestBuilder.setTypes(ESTransportClient.getIndexType());
// 设置查询类型 1.SearchType.DFS_QUERY_THEN_FETCH = 精确查询 2.SearchType.SCAN
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
// 设置查询关键词
QueryBuilder matchQuery = QueryBuilders.multiMatchQuery(keyword, "content", "title", "summary")
.type(Type.MOST_FIELDS);
searchRequestBuilder.setQuery(matchQuery);
//searchRequestBuilder.setQuery(QueryBuilders.termQuery("searchType", SearchTypeConstant.SOFTWARE));
searchRequestBuilder.setSize(0);
// QueryBuilders.t
searchRequestBuilder.setPostFilter(QueryBuilders.termQuery("searchType", SearchTypeConstant.SOFTWARE));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("category_count").field("categoryId"));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("product_count").field("productId"));
searchRequestBuilder.addAggregation(AggregationBuilders.terms("attr_count").field("attr"));
SearchResponse response = searchRequestBuilder.execute().actionGet();
1 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: