diff --git a/complaint_search/es_builders.py b/complaint_search/es_builders.py index d31bf34e..c231a120 100644 --- a/complaint_search/es_builders.py +++ b/complaint_search/es_builders.py @@ -409,8 +409,10 @@ def build(self): agg_fields = self._AGG_FIELDS if self.exclude: - agg_fields = [field_name for field_name in self._AGG_FIELDS - if field_name not in self.exclude] + agg_fields = [ + field_name for field_name in self._AGG_FIELDS + if field_name not in self.exclude or field_name in self.params + ] for field_name in agg_fields: aggs[field_name] = self.build_one(field_name) diff --git a/complaint_search/tests/expected_results/search_with_company__valid.json b/complaint_search/tests/expected_results/search_with_company__valid.json index 70a2fd85..5c416697 100644 --- a/complaint_search/tests/expected_results/search_with_company__valid.json +++ b/complaint_search/tests/expected_results/search_with_company__valid.json @@ -62,6 +62,22 @@ } }, "aggs": { + "company": { + "aggs": { + "company": { + "terms": { + "field": "company.raw", + "size": 0 + } + } + }, + "filter": { + "bool": { + "must": [], + "must_not": [] + } + } + }, "company_public_response": { "aggs": { "company_public_response": { diff --git a/complaint_search/tests/expected_results/search_with_company_agg_exclude__valid.json b/complaint_search/tests/expected_results/search_with_company_agg_exclude__valid.json index e6cbe008..6aeaecba 100644 --- a/complaint_search/tests/expected_results/search_with_company_agg_exclude__valid.json +++ b/complaint_search/tests/expected_results/search_with_company_agg_exclude__valid.json @@ -62,6 +62,22 @@ } }, "aggs": { + "company": { + "aggs": { + "company": { + "terms": { + "field": "company.raw", + "size": 0 + } + } + }, + "filter": { + "bool": { + "must": [], + "must_not": [] + } + } + }, "company_public_response": { "aggs": { "company_public_response": { diff --git a/complaint_search/tests/expected_results/search_with_zip_code__valid.json b/complaint_search/tests/expected_results/search_with_zip_code__valid.json index aa7cf38a..00149e52 100644 --- a/complaint_search/tests/expected_results/search_with_zip_code__valid.json +++ b/complaint_search/tests/expected_results/search_with_zip_code__valid.json @@ -364,6 +364,22 @@ "must_not": [] } } + }, + "zip_code": { + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 0 + } + } + }, + "filter": { + "bool": { + "must": [], + "must_not": [] + } + } } } } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_zip_code_agg_exclude__valid.json b/complaint_search/tests/expected_results/search_with_zip_code_agg_exclude__valid.json index 6a058420..268e0e80 100644 --- a/complaint_search/tests/expected_results/search_with_zip_code_agg_exclude__valid.json +++ b/complaint_search/tests/expected_results/search_with_zip_code_agg_exclude__valid.json @@ -390,6 +390,22 @@ "must_not": [] } } + }, + "zip_code": { + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 0 + } + } + }, + "filter": { + "bool": { + "must": [], + "must_not": [] + } + } } } } \ No newline at end of file