From 2ac8d6e2e28b55872ef7edde2574be45270a1714 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Thu, 22 Jun 2017 17:30:44 -0400 Subject: [PATCH 1/7] Add aggregations with filters --- complaint_search/es_interface.py | 174 +++++++++++++++++++++++++------ 1 file changed, 145 insertions(+), 29 deletions(-) diff --git a/complaint_search/es_interface.py b/complaint_search/es_interface.py index 5e2347e4..3f5d30b6 100644 --- a/complaint_search/es_interface.py +++ b/complaint_search/es_interface.py @@ -15,6 +15,23 @@ _COMPLAINT_ES_INDEX = os.environ.get('COMPLAINT_ES_INDEX', 'complaint-index') _COMPLAINT_DOC_TYPE = os.environ.get('COMPLAINT_DOC_TYPE', 'complaint-doctype') +_OPTIONAL_FILTERS = ("product", "issue", "company", "state", "zip_code", "timely", + "company_response", "company_public_response", + "consumer_consent_provided", "submitted_via", "tag") + +_OPTIONAL_FILTERS_PARAM_TO_ES_MAP = { + "product": "product.raw", + "sub_product": "sub_product.raw", + "issue": "issue.raw", + "sub_issue": "sub_issue.raw" +} +_OPTIONAL_FILTERS_CHILD_MAP = { + "product": "sub_product", + "issue": "sub_issue" +} + +_OPTIONAL_FILTERS_STRING_TO_BOOL = ("consumer_disputed", "has_narratives") + def get_es(): global _ES_INSTANCE if _ES_INSTANCE is None: @@ -22,13 +39,114 @@ def get_es(): timeout=100) return _ES_INSTANCE -def _create_and_append_bool_should_clauses(es_field_name, value_list, - filter_list, with_subitems=False, es_subitem_field_name=None): + + +def _create_aggregation(**kwargs): + + Field = namedtuple('Field', 'name title size has_subfield') + fields = [ + Field('has_narratives', 'Only show complaints with narratives?', 10, False), + Field('company', 'Matched company name', 10000, False), + Field('product', 'Product / Subproduct', 10000, True), + Field('issue', 'Issue / Subissue', 10000, True), + Field('state', 'State', 50, False), + Field('zip_code', 'Zip code', 1000, False), + Field('timely', 'Did company provide a timely response?', 10, False), + Field('company_response', 'Company response', 100, False), + Field('company_public_response', 'Company public response', 100, False), + Field('consumer_disputed', 'Did the consumer dispute the response?', 100, False), + Field('consumer_consent_provided', 'Consumer Consent', 100, False), + Field('tag', 'Tags', 100, False), + Field('submitted_via', 'How did the consumer submit the complaint to CFPB?', 100, False) + ] + aggs = {} + + for field in fields: + field_aggs = { + "filter": { + "and": { + "filters": [ + + ] + } + } + } + + es_field_name = _OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(field.name, field.name) + es_subfield_name = None + if field.has_subfield: + es_subfield_name = _OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(_OPTIONAL_FILTERS_CHILD_MAP.get(field.name)) + field_aggs["aggs"] = { + field.title: { + "terms": { + "field": es_field_name, + "size": field.size + }, + "aggs": { + es_subfield_name: { + "terms": { + "field": es_subfield_name, + "size": field.size + } + } + } + } + } + else: + field_aggs["aggs"] = { + field.title: { + "terms": { + "field": es_field_name, + "size": field.size + } + } + } + + date_filter = { + "range": { + "date_received": { + + } + } + } + if "min_date" in kwargs: + date_filter["range"]["date_received"]["from"] = kwargs["min_date"] + if "max_date" in kwargs: + date_filter["range"]["date_received"]["to"] = kwargs["max_date"] + + field_aggs["filter"]["and"]["filters"].append(date_filter) + + for item in kwargs: + if item in _OPTIONAL_FILTERS and item != field.name: + clauses = _create_and_append_bool_should_clauses(item, + kwargs[item], field_aggs["filter"]["and"]["filters"], + with_subitems=field.has_subfield, + es_subitem_field_name=es_subfield_name) + elif item in _OPTIONAL_FILTERS_STRING_TO_BOOL and item != field.name: + clauses = _create_and_append_bool_should_clauses(item, + [ 0 if cd.lower() == "no" else 1 for cd in kwargs[item] ], + field_aggs["filter"]["and"]["filters"]) + + aggs[field.title] = field_aggs + + return aggs + # for field_aggs in aggs: + # field_aggs["aggs"] = + # for field in fields: + # if field.name in kwargs: + # for field_aggs in aggs: + # if field_aggs["filter"]["and"]["filters"].append() + + + + +def _create_bool_should_clauses(es_field_name, value_list, + with_subitems=False, es_subitem_field_name=None): if value_list: if not with_subitems: term_list = [ {"terms": {es_field_name: [value]}} for value in value_list ] - filter_list.append({"bool": {"should": term_list}}) + return {"bool": {"should": term_list}} else: item_dict = defaultdict(list) for v in value_list: @@ -53,7 +171,16 @@ def _create_and_append_bool_should_clauses(es_field_name, value_list, subitem_term = {"terms": {es_subitem_field_name: subitems}} f_list.append({"and": {"filters": [item_term, subitem_term]}}) - filter_list.append({"bool": {"should": f_list}}) + return {"bool": {"should": f_list}} + +def _create_and_append_bool_should_clauses(es_field_name, value_list, + filter_list, with_subitems=False, es_subitem_field_name=None): + + filter_clauses = _create_bool_should_clauses(es_field_name, value_list, + with_subitems, es_subitem_field_name) + + if filter_clauses: + filter_list.append(filter_clauses) # List of possible arguments: # - fmt: format to be returned: "json", "csv", "xls", or "xlsx" @@ -88,23 +215,6 @@ def search(**kwargs): "sort": "relevance_desc" } - OPTIONAL_FILTERS = ("product", "issue", "company", "state", "zip_code", "timely", - "company_response", "company_public_response", - "consumer_consent_provided", "submitted_via", "tag") - - OPTIONAL_FILTERS_PARAM_TO_ES_MAP = { - "product": "product.raw", - "sub_product": "sub_product.raw", - "issue": "issue.raw", - "sub_issue": "sub_issue.raw" - } - OPTIONAL_FILTERS_CHILD_MAP = { - "product": "sub_product", - "issue": "sub_issue" - } - - OPTIONAL_FILTERS_STRING_TO_BOOL = ("consumer_disputed", "has_narratives") - params.update(**kwargs) res = None @@ -150,6 +260,9 @@ def search(**kwargs): # post-filter body["post_filter"] = {"and": {"filters": []}} + ## Create base aggregation (without filters at this point) + body["aggs"] = _create_aggregation(**kwargs) + ## date if params.get("min_date") or params.get("max_date"): date_clause = {"range": {"date_received": {}}} @@ -160,23 +273,26 @@ def search(**kwargs): body["post_filter"]["and"]["filters"].append(date_clause) - ## Create bool should clauses for fields in OPTIONAL_FILTERS - for field in OPTIONAL_FILTERS: - if field in OPTIONAL_FILTERS_CHILD_MAP: - _create_and_append_bool_should_clauses(OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(field, field), + + ## Create bool should clauses for fields in _OPTIONAL_FILTERS + for field in _OPTIONAL_FILTERS: + if field in _OPTIONAL_FILTERS_CHILD_MAP: + _create_and_append_bool_should_clauses(_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(field, field), params.get(field), body["post_filter"]["and"]["filters"], with_subitems=True, - es_subitem_field_name=OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(OPTIONAL_FILTERS_CHILD_MAP.get(field), - OPTIONAL_FILTERS_CHILD_MAP.get(field))) + es_subitem_field_name=_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(_OPTIONAL_FILTERS_CHILD_MAP.get(field), + _OPTIONAL_FILTERS_CHILD_MAP.get(field))) else: - _create_and_append_bool_should_clauses(OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(field, field), + _create_and_append_bool_should_clauses(_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(field, field), params.get(field), body["post_filter"]["and"]["filters"]) - for field in OPTIONAL_FILTERS_STRING_TO_BOOL: + for field in _OPTIONAL_FILTERS_STRING_TO_BOOL: if params.get(field): _create_and_append_bool_should_clauses(field, [ 0 if cd.lower() == "no" else 1 for cd in params.get(field) ], body["post_filter"]["and"]["filters"]) + print "***TEST body" + print body # format if params.get("fmt") == "json": res = get_es().search(index=_COMPLAINT_ES_INDEX, body=body) From e8366a78b2c38a5cc1bd52916078d6bee7317169 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Sun, 25 Jun 2017 03:16:18 -0400 Subject: [PATCH 2/7] Update tests with aggregations --- complaint_search/es_interface.py | 20 +- complaint_search/tests/test_es_interface.py | 9178 +++++++++++++++++-- requirements_test.txt | 3 +- 3 files changed, 8661 insertions(+), 540 deletions(-) diff --git a/complaint_search/es_interface.py b/complaint_search/es_interface.py index 3f5d30b6..17a72c70 100644 --- a/complaint_search/es_interface.py +++ b/complaint_search/es_interface.py @@ -61,6 +61,7 @@ def _create_aggregation(**kwargs): ] aggs = {} + # Creating aggregation object for each field above for field in fields: field_aggs = { "filter": { @@ -118,27 +119,18 @@ def _create_aggregation(**kwargs): for item in kwargs: if item in _OPTIONAL_FILTERS and item != field.name: - clauses = _create_and_append_bool_should_clauses(item, + clauses = _create_and_append_bool_should_clauses(_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(item, item), kwargs[item], field_aggs["filter"]["and"]["filters"], - with_subitems=field.has_subfield, - es_subitem_field_name=es_subfield_name) + with_subitems=item in _OPTIONAL_FILTERS_CHILD_MAP, + es_subitem_field_name=_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(_OPTIONAL_FILTERS_CHILD_MAP.get(item))) elif item in _OPTIONAL_FILTERS_STRING_TO_BOOL and item != field.name: - clauses = _create_and_append_bool_should_clauses(item, + clauses = _create_and_append_bool_should_clauses(_OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(item, item), [ 0 if cd.lower() == "no" else 1 for cd in kwargs[item] ], field_aggs["filter"]["and"]["filters"]) aggs[field.title] = field_aggs return aggs - # for field_aggs in aggs: - # field_aggs["aggs"] = - # for field in fields: - # if field.name in kwargs: - # for field_aggs in aggs: - # if field_aggs["filter"]["and"]["filters"].append() - - - def _create_bool_should_clauses(es_field_name, value_list, with_subitems=False, es_subitem_field_name=None): @@ -291,8 +283,6 @@ def search(**kwargs): [ 0 if cd.lower() == "no" else 1 for cd in params.get(field) ], body["post_filter"]["and"]["filters"]) - print "***TEST body" - print body # format if params.get("fmt") == "json": res = get_es().search(index=_COMPLAINT_ES_INDEX, body=body) diff --git a/complaint_search/tests/test_es_interface.py b/complaint_search/tests/test_es_interface.py index 3cf224e7..e02965a0 100644 --- a/complaint_search/tests/test_es_interface.py +++ b/complaint_search/tests/test_es_interface.py @@ -5,6 +5,7 @@ import os import urllib import json +import deep import mock class EsInterfaceTest(TestCase): @@ -36,11 +37,307 @@ def test_search_no_param__valid(self, mock_rget, mock_search): "fragment_size": 500 }, "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } } res = search() - mock_search.assert_called_once_with(body=body, - index='INDEX') + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') mock_rget.assert_not_called() self.assertEqual('OK', res) @@ -51,8 +348,11 @@ def test_search_no_param__valid(self, mock_rget, mock_search): @mock.patch("complaint_search.es_interface._COMPLAINT_DOC_TYPE", "DOC_TYPE") @mock.patch.object(Elasticsearch, 'search') @mock.patch('requests.get', ok=True, content="RGET_OK") - def test_search_with_fmt_nonjson__valid(self, mock_rget, mock_search): + @mock.patch('json.dumps') + @mock.patch('urllib.urlencode') + def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_rget, mock_search): mock_search.return_value = 'OK' + mock_jdump.return_value = 'JDUMPS_OK' body = { "from": 0, "size": 10, @@ -73,14 +373,317 @@ def test_search_with_fmt_nonjson__valid(self, mock_rget, mock_search): "fragment_size": 500 }, "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } } for fmt in ["csv", "xls", "xlsx"]: res = search(fmt=fmt) - param = urllib.urlencode({"format": fmt, "source": json.dumps(body)}) - other_args = {"auth": ("ES_USER", "ES_PASSWORD"), "verify": False, "timeout": 30} - url = "ES_URL/INDEX/DOC_TYPE/_data?{}".format(param) - mock_rget.assert_any_call(url, **other_args) + self.assertEqual(len(mock_jdump.call_args), 2) + self.assertEqual(1, len(mock_jdump.call_args[0])) + act_body = mock_jdump.call_args[0][0] + diff = deep.diff(body, act_body) + if diff: + print "fmt={}".format(fmt) + diff.print_full() + self.assertEqual(len(mock_urlencode.call_args), 2) + self.assertEqual(1, len(mock_urlencode.call_args[0])) + param = {"format": fmt, "source": "JDUMPS_OK"} + act_param = mock_urlencode.call_args[0][0] + self.assertEqual(param, act_param) + + self.assertEqual(mock_jdump.call_count, 3) + self.assertEqual(mock_urlencode.call_count, 3) mock_search.assert_not_called() self.assertEqual(3, mock_rget.call_count) @@ -109,60 +712,326 @@ def test_search_with_field__valid(self, mock_search): "fragment_size": 500 }, "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} - } - res = search(field="test_field") - mock_search.assert_called_once_with(body=body, - index='INDEX') - self.assertEqual('OK', res) - - @mock.patch.object(Elasticsearch, 'search') - @mock.patch('requests.get', ok=True, content="RGET_OK") - def test_search_with_fmt__invalid(self, mock_rget, mock_search): - mock_search.return_value = 'OK' - res = search(fmt="pdf") - self.assertIsNone(res) - mock_search.assert_not_called() - mock_rget.assert_not_called() - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_size__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 40, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } - res = search(size=40) - mock_search.assert_called_once_with(body=body, - index="INDEX") + res = search(field="test_field") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) + @mock.patch.object(Elasticsearch, 'search') + @mock.patch('requests.get', ok=True, content="RGET_OK") + def test_search_with_fmt__invalid(self, mock_rget, mock_search): + mock_search.return_value = 'OK' + res = search(fmt="pdf") + self.assertIsNone(res) + mock_search.assert_not_called() + mock_rget.assert_not_called() + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @mock.patch.object(Elasticsearch, 'search') - def test_search_with_frm__valid(self, mock_search): + def test_search_with_size__valid(self, mock_search): mock_search.return_value = 'OK' body = { - "from": 20, - "size": 10, + "from": 0, + "size": 40, "query": { "query_string": { "query": "*", @@ -180,20 +1049,311 @@ def test_search_with_frm__valid(self, mock_search): "fragment_size": 500 }, "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } } - res = search(frm=20) + res = search(size=40) mock_search.assert_called_once_with(body=body, index="INDEX") self.assertEqual('OK', res) - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @mock.patch.object(Elasticsearch, 'search') - def test_search_with_sort__valid(self, mock_search): + def test_search_with_frm__valid(self, mock_search): mock_search.return_value = 'OK' body = { - "from": 0, + "from": 20, "size": 10, "query": { "query_string": { @@ -211,12 +1371,632 @@ def test_search_with_sort__valid(self, mock_search): "number_of_fragments": 1, "fragment_size": 500 }, - "post_filter": {"and": {"filters": []}} - } - - sort_fields = [ - ("relevance_desc", "_score", "desc"), - ("relevance_asc", "_score", "asc"), + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(frm=20) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_sort__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + + sort_fields = [ + ("relevance_desc", "_score", "desc"), + ("relevance_asc", "_score", "asc"), ("created_date_desc", "created_date", "desc"), ("created_date_asc", "created_date", "asc") ] @@ -241,88 +2021,5234 @@ def test_search_with_search_term__valid(self, mock_search): "query": "test_term", "operator": "and" } - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(search_term="test_term") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_min_date__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(min_date="2014-04-14") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_max_date__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(max_date="2017-04-14") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_company__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(company=["Bank 1", "Second Bank"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "company" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_product__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(product=["Payday Loan", u"Mortgage\u2022FHA Mortgage"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "product" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_issue__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(issue=[u"Communication tactics\u2022Frequent or repeated calls", + "Loan servicing, payments, escrow account"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "issue" + diff.print_full() + print "body" + print body + print "act_body" + print act_body + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_state__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(state=["CA", "VA", "OR"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "state" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_zip_code__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(zip_code=["12345", "23435", "03433"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "zip_code" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_timely__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(timely=["Yes", "No"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "timely" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_company_response__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(company_response=["Closed", "No response"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "company_response" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_company_public_response__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response": ["Response 1"]}}, + {"terms": {"company_public_response": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } + res = search(company_public_response=["Response 1", "Response 2"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "company_public_response" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) + + @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") + @mock.patch.object(Elasticsearch, 'search') + def test_search_with_consumer_consent_provided__valid(self, mock_search): + mock_search.return_value = 'OK' + body = { + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + }] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}} - } - res = search(search_term="test_term") - mock_search.assert_called_once_with(body=body, - index='INDEX') - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_min_date__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided": ["yes"]}}, + {"terms": {"consumer_consent_provided": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": [{"range": {"date_received": {"from": "2014-04-14"}}}]}} - } - res = search(min_date="2014-04-14") - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_max_date__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": [{"range": {"date_received": {"to": "2017-04-14"}}}]}} + } } - res = search(max_date="2017-04-14") - mock_search.assert_called_once_with(body=body, - index="INDEX") + res = search(consumer_consent_provided=["yes", "no"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "consumer_consent_provided" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @mock.patch.object(Elasticsearch, 'search') - def test_search_with_company__valid(self, mock_search): + def test_search_with_submitted_via__valid(self, mock_search): mock_search.return_value = 'OK' body = { "from": 0, @@ -349,123 +7275,419 @@ def test_search_with_company__valid(self, mock_search): "filters": [{ "bool": { "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} ] } }] } - } - } - res = search(company=["Bank 1", "Second Bank"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_product__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } }, - "highlight": { - "fields": { - "complaint_what_happened": {} + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, + "Matched company name": { + "filter": { + "and": { + "filters": [ { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} ] } } ] } - }] - } - } - } - res = search(product=["Payday Loan", u"Mortgage\u2022FHA Mortgage"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_issue__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] + "range": { + "date_received": {} } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + } ] } - }] + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } } + } } - res = search(issue=[u"Communication tactics\u2022Frequent or repeated calls", - "Loan servicing, payments, escrow account"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) + res = search(submitted_via=["mail", "web"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "submitted_via" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') + self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @mock.patch.object(Elasticsearch, 'search') - def test_search_with_state__valid(self, mock_search): + def test_search_with_tag__valid(self, mock_search): mock_search.return_value = 'OK' body = { "from": 0, @@ -492,108 +7714,419 @@ def test_search_with_state__valid(self, mock_search): "filters": [{ "bool": { "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} ] } }] } - } - } - res = search(state=["CA", "VA", "OR"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_zip_code__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } }, - "highlight": { - "fields": { - "complaint_what_happened": {} + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } ] } - }] - } - } - } - res = search(zip_code=["12345", "23435", "03433"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_timely__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } ] } - }] + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } } + } } - res = search(timely=["Yes", "No"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") + res = search(tag=["Older American", "Servicemember"]) + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "tag" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @mock.patch.object(Elasticsearch, 'search') - def test_search_with_company_response__valid(self, mock_search): + def test_search_with_consumer_disputed__valid(self, mock_search): mock_search.return_value = 'OK' body = { "from": 0, @@ -620,227 +8153,414 @@ def test_search_with_company_response__valid(self, mock_search): "filters": [{ "bool": { "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} ] } }] } - } - } - res = search(company_response=["Closed", "No response"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_company_public_response__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } }, - "highlight": { - "fields": { - "complaint_what_happened": {} + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } ] } - }] - } - } - } - res = search(company_public_response=["Response 1", "Response 2"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_consumer_consent_provided__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } ] } - }] - } - } - } - res = search(consumer_consent_provided=["yes", "no"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_submitted_via__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } ] } - }] - } - } - } - res = search(submitted_via=["mail", "web"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_tag__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } ] } - }] - } - } - } - res = search(tag=["Older American", "Servicemember"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") - self.assertEqual('OK', res) - - @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") - @mock.patch.object(Elasticsearch, 'search') - def test_search_with_consumer_disputed__valid(self, mock_search): - mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } ] } - }] + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } } + } } res = search(consumer_disputed=["No", "Yes"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "consumer_disputed" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @@ -878,11 +8598,408 @@ def test_search_with_has_narratives__valid(self, mock_search): } }] } + }, + "aggs": { + "Only show complaints with narratives?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "Only show complaints with narratives?": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "Matched company name": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Matched company name": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "Product / Subproduct": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Product / Subproduct": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "Issue / Subissue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Issue / Subissue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "State": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "State": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "Zip code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Zip code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "Did company provide a timely response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Did company provide a timely response?": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "Company response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Company response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "Company public response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Company public response": { + "terms": { + "field": "company_public_response", + "size": 100 + } + } + } + }, + "Did the consumer dispute the response?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Did the consumer dispute the response?": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "Consumer Consent": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Consumer Consent": { + "terms": { + "field": "consumer_consent_provided", + "size": 100 + } + } + } + }, + "Tags": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "Tags": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "How did the consumer submit the complaint to CFPB?": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "How did the consumer submit the complaint to CFPB?": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + } } res = search(has_narratives=["No", "Yes"]) - mock_search.assert_called_once_with(body=body, - index="INDEX") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(2, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + diff = deep.diff(body, act_body) + if diff: + print "has_narratives" + diff.print_full() + self.assertIsNone(deep.diff(body, act_body)) + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @@ -901,8 +9018,12 @@ def test_suggest_with_text__valid(self, mock_suggest): mock_suggest.return_value = 'OK' body = {"sgg": {"text": "Mortgage", "completion": {"field": "suggest", "size": 6}}} res = suggest(text="Mortgage") - mock_suggest.assert_called_once_with(body=body, - index="INDEX") + self.assertEqual(len(mock_suggest.call_args), 2) + self.assertEqual(0, len(mock_suggest.call_args[0])) + self.assertEqual(2, len(mock_suggest.call_args[1])) + act_body = mock_suggest.call_args[1]['body'] + self.assertDictEqual(mock_suggest.call_args[1]['body'], body) + self.assertEqual(mock_suggest.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @@ -911,8 +9032,12 @@ def test_suggest_with_size__valid(self, mock_suggest): mock_suggest.return_value = 'OK' body = {"sgg": {"text": "Loan", "completion": {"field": "suggest", "size": 10}}} res = suggest(text="Loan", size=10) - mock_suggest.assert_called_once_with(body=body, - index="INDEX") + self.assertEqual(len(mock_suggest.call_args), 2) + self.assertEqual(0, len(mock_suggest.call_args[0])) + self.assertEqual(2, len(mock_suggest.call_args[1])) + act_body = mock_suggest.call_args[1]['body'] + self.assertDictEqual(mock_suggest.call_args[1]['body'], body) + self.assertEqual(mock_suggest.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) @mock.patch("complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX") @@ -922,6 +9047,11 @@ def test_document__valid(self, mock_search): mock_search.return_value = 'OK' body = {"query": {"term": {"_id": 123456}}} res = document(123456) - mock_search.assert_called_once_with(body=body, doc_type="DOC_TYPE", - index="INDEX") + self.assertEqual(len(mock_search.call_args), 2) + self.assertEqual(0, len(mock_search.call_args[0])) + self.assertEqual(3, len(mock_search.call_args[1])) + act_body = mock_search.call_args[1]['body'] + self.assertDictEqual(mock_search.call_args[1]['body'], body) + self.assertEqual(mock_search.call_args[1]['doc_type'], 'DOC_TYPE') + self.assertEqual(mock_search.call_args[1]['index'], 'INDEX') self.assertEqual('OK', res) \ No newline at end of file diff --git a/requirements_test.txt b/requirements_test.txt index 6eb6461c..421cfbeb 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1 +1,2 @@ -mock==2.0.0 \ No newline at end of file +mock==2.0.0 +deep==0.10 \ No newline at end of file From c77711adcbe1d016fd28d32a72e98413922f4fd1 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Wed, 28 Jun 2017 20:11:06 -0400 Subject: [PATCH 3/7] Use raw for company_public_response and consumer_consent_provided --- complaint_search/es_interface.py | 4 +- complaint_search/tests/test_es_interface.py | 196 ++++++++++---------- 2 files changed, 101 insertions(+), 99 deletions(-) diff --git a/complaint_search/es_interface.py b/complaint_search/es_interface.py index 17a72c70..76262e33 100644 --- a/complaint_search/es_interface.py +++ b/complaint_search/es_interface.py @@ -23,7 +23,9 @@ "product": "product.raw", "sub_product": "sub_product.raw", "issue": "issue.raw", - "sub_issue": "sub_issue.raw" + "sub_issue": "sub_issue.raw", + "company_public_response": "company_public_response.raw", + "consumer_consent_provided": "consumer_consent_provided.raw" } _OPTIONAL_FILTERS_CHILD_MAP = { "product": "sub_product", diff --git a/complaint_search/tests/test_es_interface.py b/complaint_search/tests/test_es_interface.py index e02965a0..a3e0b0d6 100644 --- a/complaint_search/tests/test_es_interface.py +++ b/complaint_search/tests/test_es_interface.py @@ -238,7 +238,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -280,7 +280,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -574,7 +574,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -616,7 +616,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -913,7 +913,7 @@ def test_search_with_field__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -955,7 +955,7 @@ def test_search_with_field__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -1250,7 +1250,7 @@ def test_search_with_size__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -1292,7 +1292,7 @@ def test_search_with_size__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -1573,7 +1573,7 @@ def test_search_with_frm__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -1615,7 +1615,7 @@ def test_search_with_frm__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -1900,7 +1900,7 @@ def test_search_with_sort__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -1942,7 +1942,7 @@ def test_search_with_sort__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -2232,7 +2232,7 @@ def test_search_with_search_term__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -2274,7 +2274,7 @@ def test_search_with_search_term__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -2589,7 +2589,7 @@ def test_search_with_min_date__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -2635,7 +2635,7 @@ def test_search_with_min_date__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -2954,7 +2954,7 @@ def test_search_with_max_date__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -3000,7 +3000,7 @@ def test_search_with_max_date__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -3366,7 +3366,7 @@ def test_search_with_company__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -3424,7 +3424,7 @@ def test_search_with_company__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -3880,7 +3880,7 @@ def test_search_with_product__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -3954,7 +3954,7 @@ def test_search_with_product__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -4414,7 +4414,7 @@ def test_search_with_issue__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -4486,7 +4486,7 @@ def test_search_with_issue__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -4895,7 +4895,7 @@ def test_search_with_state__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -4955,7 +4955,7 @@ def test_search_with_state__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -5347,7 +5347,7 @@ def test_search_with_zip_code__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -5407,7 +5407,7 @@ def test_search_with_zip_code__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -5790,7 +5790,7 @@ def test_search_with_timely__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -5848,7 +5848,7 @@ def test_search_with_timely__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -6229,7 +6229,7 @@ def test_search_with_company_response__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -6287,7 +6287,7 @@ def test_search_with_company_response__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -6397,8 +6397,8 @@ def test_search_with_company_public_response__valid(self, mock_search): "filters": [{ "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } }] @@ -6417,8 +6417,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6446,8 +6446,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6475,8 +6475,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6512,8 +6512,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6549,8 +6549,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6578,8 +6578,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6607,8 +6607,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6636,8 +6636,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6668,7 +6668,7 @@ def test_search_with_company_public_response__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -6686,8 +6686,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6715,8 +6715,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6726,7 +6726,7 @@ def test_search_with_company_public_response__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -6744,8 +6744,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6773,8 +6773,8 @@ def test_search_with_company_public_response__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"company_public_response": ["Response 1"]}}, - {"terms": {"company_public_response": ["Response 2"]}} + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} ] } } @@ -6800,7 +6800,7 @@ def test_search_with_company_public_response__valid(self, mock_search): act_body = mock_search.call_args[1]['body'] diff = deep.diff(body, act_body) if diff: - print "company_public_response" + print "company_public_response.raw" diff.print_full() self.assertIsNone(deep.diff(body, act_body)) self.assertDictEqual(mock_search.call_args[1]['body'], body) @@ -6836,8 +6836,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): "filters": [{ "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } }] @@ -6856,8 +6856,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -6885,8 +6885,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -6914,8 +6914,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -6951,8 +6951,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -6988,8 +6988,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7017,8 +7017,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7046,8 +7046,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7075,8 +7075,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7104,8 +7104,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7115,7 +7115,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -7133,8 +7133,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7165,7 +7165,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -7183,8 +7183,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7212,8 +7212,8 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): { "bool": { "should": [ - {"terms": {"consumer_consent_provided": ["yes"]}}, - {"terms": {"consumer_consent_provided": ["no"]}} + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} ] } } @@ -7239,7 +7239,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): act_body = mock_search.call_args[1]['body'] diff = deep.diff(body, act_body) if diff: - print "consumer_consent_provided" + print "consumer_consent_provided.raw" diff.print_full() self.assertIsNone(deep.diff(body, act_body)) self.assertDictEqual(mock_search.call_args[1]['body'], body) @@ -7554,7 +7554,7 @@ def test_search_with_submitted_via__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -7612,7 +7612,7 @@ def test_search_with_submitted_via__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -7993,7 +7993,7 @@ def test_search_with_tag__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -8051,7 +8051,7 @@ def test_search_with_tag__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -8432,7 +8432,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -8482,7 +8482,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } @@ -8863,7 +8863,7 @@ def test_search_with_has_narratives__valid(self, mock_search): "aggs": { "Company public response": { "terms": { - "field": "company_public_response", + "field": "company_public_response.raw", "size": 100 } } @@ -8921,7 +8921,7 @@ def test_search_with_has_narratives__valid(self, mock_search): "aggs": { "Consumer Consent": { "terms": { - "field": "consumer_consent_provided", + "field": "consumer_consent_provided.raw", "size": 100 } } From 47fabc2de988386a3bcecda39886dfb073bea853 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Thu, 29 Jun 2017 00:51:55 -0400 Subject: [PATCH 4/7] Remove title in aggs, and use field name instead --- complaint_search/es_interface.py | 34 +- complaint_search/tests/test_es_interface.py | 1144 +++++++++---------- 2 files changed, 589 insertions(+), 589 deletions(-) diff --git a/complaint_search/es_interface.py b/complaint_search/es_interface.py index 76262e33..2b1db47f 100644 --- a/complaint_search/es_interface.py +++ b/complaint_search/es_interface.py @@ -45,21 +45,21 @@ def get_es(): def _create_aggregation(**kwargs): - Field = namedtuple('Field', 'name title size has_subfield') + Field = namedtuple('Field', 'name size has_subfield') fields = [ - Field('has_narratives', 'Only show complaints with narratives?', 10, False), - Field('company', 'Matched company name', 10000, False), - Field('product', 'Product / Subproduct', 10000, True), - Field('issue', 'Issue / Subissue', 10000, True), - Field('state', 'State', 50, False), - Field('zip_code', 'Zip code', 1000, False), - Field('timely', 'Did company provide a timely response?', 10, False), - Field('company_response', 'Company response', 100, False), - Field('company_public_response', 'Company public response', 100, False), - Field('consumer_disputed', 'Did the consumer dispute the response?', 100, False), - Field('consumer_consent_provided', 'Consumer Consent', 100, False), - Field('tag', 'Tags', 100, False), - Field('submitted_via', 'How did the consumer submit the complaint to CFPB?', 100, False) + Field('has_narratives', 10, False), + Field('company', 10000, False), + Field('product', 10000, True), + Field('issue', 10000, True), + Field('state', 50, False), + Field('zip_code', 1000, False), + Field('timely', 10, False), + Field('company_response', 100, False), + Field('company_public_response', 100, False), + Field('consumer_disputed', 100, False), + Field('consumer_consent_provided', 100, False), + Field('tag', 100, False), + Field('submitted_via', 100, False) ] aggs = {} @@ -80,7 +80,7 @@ def _create_aggregation(**kwargs): if field.has_subfield: es_subfield_name = _OPTIONAL_FILTERS_PARAM_TO_ES_MAP.get(_OPTIONAL_FILTERS_CHILD_MAP.get(field.name)) field_aggs["aggs"] = { - field.title: { + field.name: { "terms": { "field": es_field_name, "size": field.size @@ -97,7 +97,7 @@ def _create_aggregation(**kwargs): } else: field_aggs["aggs"] = { - field.title: { + field.name: { "terms": { "field": es_field_name, "size": field.size @@ -130,7 +130,7 @@ def _create_aggregation(**kwargs): [ 0 if cd.lower() == "no" else 1 for cd in kwargs[item] ], field_aggs["filter"]["and"]["filters"]) - aggs[field.title] = field_aggs + aggs[field.name] = field_aggs return aggs diff --git a/complaint_search/tests/test_es_interface.py b/complaint_search/tests/test_es_interface.py index a3e0b0d6..7caf6c16 100644 --- a/complaint_search/tests/test_es_interface.py +++ b/complaint_search/tests/test_es_interface.py @@ -39,7 +39,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -52,7 +52,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -60,7 +60,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -73,7 +73,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -81,7 +81,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -94,7 +94,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -110,7 +110,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -123,7 +123,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -139,7 +139,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -152,7 +152,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -160,7 +160,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -173,7 +173,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -181,7 +181,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -194,7 +194,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -202,7 +202,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -215,7 +215,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -223,7 +223,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -236,7 +236,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -244,7 +244,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -257,7 +257,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -265,7 +265,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -278,7 +278,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -286,7 +286,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -299,7 +299,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -307,7 +307,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -320,7 +320,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -375,7 +375,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -388,7 +388,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -396,7 +396,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -409,7 +409,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -417,7 +417,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -430,7 +430,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -446,7 +446,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -459,7 +459,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -475,7 +475,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -488,7 +488,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -496,7 +496,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -509,7 +509,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -517,7 +517,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -530,7 +530,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -538,7 +538,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -551,7 +551,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -559,7 +559,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -572,7 +572,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -580,7 +580,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -593,7 +593,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -601,7 +601,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -614,7 +614,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -622,7 +622,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -635,7 +635,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -643,7 +643,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -656,7 +656,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -714,7 +714,7 @@ def test_search_with_field__valid(self, mock_search): "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -727,7 +727,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -735,7 +735,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -748,7 +748,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -756,7 +756,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -769,7 +769,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -785,7 +785,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -798,7 +798,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -814,7 +814,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -827,7 +827,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -835,7 +835,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -848,7 +848,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -856,7 +856,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -869,7 +869,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -877,7 +877,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -890,7 +890,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -898,7 +898,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -911,7 +911,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -919,7 +919,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -932,7 +932,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -940,7 +940,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -953,7 +953,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -961,7 +961,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -974,7 +974,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -982,7 +982,7 @@ def test_search_with_field__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -995,7 +995,7 @@ def test_search_with_field__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -1051,7 +1051,7 @@ def test_search_with_size__valid(self, mock_search): "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -1064,7 +1064,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -1072,7 +1072,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -1085,7 +1085,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -1093,7 +1093,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -1106,7 +1106,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -1122,7 +1122,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -1135,7 +1135,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -1151,7 +1151,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -1164,7 +1164,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -1172,7 +1172,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -1185,7 +1185,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -1193,7 +1193,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -1206,7 +1206,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -1214,7 +1214,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -1227,7 +1227,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -1235,7 +1235,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -1248,7 +1248,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -1256,7 +1256,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -1269,7 +1269,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -1277,7 +1277,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -1290,7 +1290,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -1298,7 +1298,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -1311,7 +1311,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -1319,7 +1319,7 @@ def test_search_with_size__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -1332,7 +1332,7 @@ def test_search_with_size__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -1374,7 +1374,7 @@ def test_search_with_frm__valid(self, mock_search): "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -1387,7 +1387,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -1395,7 +1395,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -1408,7 +1408,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -1416,7 +1416,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -1429,7 +1429,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -1445,7 +1445,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -1458,7 +1458,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -1474,7 +1474,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -1487,7 +1487,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -1495,7 +1495,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -1508,7 +1508,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -1516,7 +1516,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -1529,7 +1529,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -1537,7 +1537,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -1550,7 +1550,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -1558,7 +1558,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -1571,7 +1571,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -1579,7 +1579,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -1592,7 +1592,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -1600,7 +1600,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -1613,7 +1613,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -1621,7 +1621,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -1634,7 +1634,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -1642,7 +1642,7 @@ def test_search_with_frm__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -1655,7 +1655,7 @@ def test_search_with_frm__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -1701,7 +1701,7 @@ def test_search_with_sort__valid(self, mock_search): }, "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -1714,7 +1714,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -1722,7 +1722,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -1735,7 +1735,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -1743,7 +1743,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -1756,7 +1756,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -1772,7 +1772,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -1785,7 +1785,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -1801,7 +1801,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -1814,7 +1814,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -1822,7 +1822,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -1835,7 +1835,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -1843,7 +1843,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -1856,7 +1856,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -1864,7 +1864,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -1877,7 +1877,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -1885,7 +1885,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -1898,7 +1898,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -1906,7 +1906,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -1919,7 +1919,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -1927,7 +1927,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -1940,7 +1940,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -1948,7 +1948,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -1961,7 +1961,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -1969,7 +1969,7 @@ def test_search_with_sort__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -1982,7 +1982,7 @@ def test_search_with_sort__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -2033,7 +2033,7 @@ def test_search_with_search_term__valid(self, mock_search): "sort": [{"_score": {"order": "desc"}}], "post_filter": {"and": {"filters": []}}, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -2046,7 +2046,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -2054,7 +2054,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -2067,7 +2067,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -2075,7 +2075,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -2088,7 +2088,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -2104,7 +2104,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -2117,7 +2117,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -2133,7 +2133,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -2146,7 +2146,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -2154,7 +2154,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -2167,7 +2167,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -2175,7 +2175,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -2188,7 +2188,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -2196,7 +2196,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -2209,7 +2209,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -2217,7 +2217,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -2230,7 +2230,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -2238,7 +2238,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -2251,7 +2251,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -2259,7 +2259,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -2272,7 +2272,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -2280,7 +2280,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -2293,7 +2293,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -2301,7 +2301,7 @@ def test_search_with_search_term__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -2314,7 +2314,7 @@ def test_search_with_search_term__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -2372,7 +2372,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -2387,7 +2387,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -2395,7 +2395,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -2410,7 +2410,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -2418,7 +2418,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -2433,7 +2433,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -2449,7 +2449,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -2464,7 +2464,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -2480,7 +2480,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -2495,7 +2495,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -2503,7 +2503,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -2518,7 +2518,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -2526,7 +2526,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -2541,7 +2541,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -2549,7 +2549,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -2564,7 +2564,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -2572,7 +2572,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -2587,7 +2587,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -2595,7 +2595,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -2610,7 +2610,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -2618,7 +2618,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -2633,7 +2633,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -2641,7 +2641,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -2656,7 +2656,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -2664,7 +2664,7 @@ def test_search_with_min_date__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -2679,7 +2679,7 @@ def test_search_with_min_date__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -2737,7 +2737,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -2752,7 +2752,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -2760,7 +2760,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -2775,7 +2775,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -2783,7 +2783,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -2798,7 +2798,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -2814,7 +2814,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -2829,7 +2829,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -2845,7 +2845,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -2860,7 +2860,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -2868,7 +2868,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -2883,7 +2883,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -2891,7 +2891,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -2906,7 +2906,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -2914,7 +2914,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -2929,7 +2929,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -2937,7 +2937,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -2952,7 +2952,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -2960,7 +2960,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -2975,7 +2975,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -2983,7 +2983,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -2998,7 +2998,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -3006,7 +3006,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -3021,7 +3021,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -3029,7 +3029,7 @@ def test_search_with_max_date__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -3044,7 +3044,7 @@ def test_search_with_max_date__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -3103,7 +3103,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -3124,7 +3124,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -3132,7 +3132,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -3145,7 +3145,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -3153,7 +3153,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -3174,7 +3174,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -3190,7 +3190,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -3211,7 +3211,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -3227,7 +3227,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -3248,7 +3248,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -3256,7 +3256,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -3277,7 +3277,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -3285,7 +3285,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -3306,7 +3306,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -3314,7 +3314,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -3335,7 +3335,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -3343,7 +3343,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -3364,7 +3364,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -3372,7 +3372,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -3393,7 +3393,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -3401,7 +3401,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -3422,7 +3422,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -3430,7 +3430,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -3451,7 +3451,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -3459,7 +3459,7 @@ def test_search_with_company__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -3480,7 +3480,7 @@ def test_search_with_company__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -3553,7 +3553,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -3582,7 +3582,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -3590,7 +3590,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -3619,7 +3619,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -3627,7 +3627,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -3640,7 +3640,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -3656,7 +3656,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -3685,7 +3685,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -3701,7 +3701,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -3730,7 +3730,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -3738,7 +3738,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -3767,7 +3767,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -3775,7 +3775,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -3804,7 +3804,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -3812,7 +3812,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -3841,7 +3841,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -3849,7 +3849,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -3878,7 +3878,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -3886,7 +3886,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -3915,7 +3915,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -3923,7 +3923,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -3952,7 +3952,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -3960,7 +3960,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -3989,7 +3989,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -3997,7 +3997,7 @@ def test_search_with_product__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -4026,7 +4026,7 @@ def test_search_with_product__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -4095,7 +4095,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -4123,7 +4123,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -4131,7 +4131,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -4159,7 +4159,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -4167,7 +4167,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -4195,7 +4195,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -4211,7 +4211,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -4224,7 +4224,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -4240,7 +4240,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -4268,7 +4268,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -4276,7 +4276,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -4304,7 +4304,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -4312,7 +4312,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -4340,7 +4340,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -4348,7 +4348,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -4376,7 +4376,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -4384,7 +4384,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -4412,7 +4412,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -4420,7 +4420,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -4448,7 +4448,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -4456,7 +4456,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -4484,7 +4484,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -4492,7 +4492,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -4520,7 +4520,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -4528,7 +4528,7 @@ def test_search_with_issue__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -4556,7 +4556,7 @@ def test_search_with_issue__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -4624,7 +4624,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -4646,7 +4646,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -4654,7 +4654,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -4676,7 +4676,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -4684,7 +4684,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -4706,7 +4706,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -4722,7 +4722,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -4744,7 +4744,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -4760,7 +4760,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -4773,7 +4773,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -4781,7 +4781,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -4803,7 +4803,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -4811,7 +4811,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -4833,7 +4833,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -4841,7 +4841,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -4863,7 +4863,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -4871,7 +4871,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -4893,7 +4893,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -4901,7 +4901,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -4923,7 +4923,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -4931,7 +4931,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -4953,7 +4953,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -4961,7 +4961,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -4983,7 +4983,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -4991,7 +4991,7 @@ def test_search_with_state__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -5013,7 +5013,7 @@ def test_search_with_state__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -5076,7 +5076,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -5098,7 +5098,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -5106,7 +5106,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -5128,7 +5128,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -5136,7 +5136,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -5158,7 +5158,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -5174,7 +5174,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -5196,7 +5196,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -5212,7 +5212,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -5234,7 +5234,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -5242,7 +5242,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -5255,7 +5255,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -5263,7 +5263,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -5285,7 +5285,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -5293,7 +5293,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -5315,7 +5315,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -5323,7 +5323,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -5345,7 +5345,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -5353,7 +5353,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -5375,7 +5375,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -5383,7 +5383,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -5405,7 +5405,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -5413,7 +5413,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -5435,7 +5435,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -5443,7 +5443,7 @@ def test_search_with_zip_code__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -5465,7 +5465,7 @@ def test_search_with_zip_code__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -5527,7 +5527,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -5548,7 +5548,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -5556,7 +5556,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -5577,7 +5577,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -5585,7 +5585,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -5606,7 +5606,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -5622,7 +5622,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -5643,7 +5643,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -5659,7 +5659,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -5680,7 +5680,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -5688,7 +5688,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -5709,7 +5709,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -5717,7 +5717,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -5730,7 +5730,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -5738,7 +5738,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -5759,7 +5759,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -5767,7 +5767,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -5788,7 +5788,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -5796,7 +5796,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -5817,7 +5817,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -5825,7 +5825,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -5846,7 +5846,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -5854,7 +5854,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -5875,7 +5875,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -5883,7 +5883,7 @@ def test_search_with_timely__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -5904,7 +5904,7 @@ def test_search_with_timely__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -5966,7 +5966,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -5987,7 +5987,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -5995,7 +5995,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -6016,7 +6016,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -6024,7 +6024,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -6045,7 +6045,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -6061,7 +6061,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -6082,7 +6082,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -6098,7 +6098,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -6119,7 +6119,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -6127,7 +6127,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -6148,7 +6148,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -6156,7 +6156,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -6177,7 +6177,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -6185,7 +6185,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -6198,7 +6198,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -6206,7 +6206,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -6227,7 +6227,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -6235,7 +6235,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -6256,7 +6256,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -6264,7 +6264,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -6285,7 +6285,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -6293,7 +6293,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -6314,7 +6314,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -6322,7 +6322,7 @@ def test_search_with_company_response__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -6343,7 +6343,7 @@ def test_search_with_company_response__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -6405,7 +6405,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -6426,7 +6426,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -6434,7 +6434,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -6455,7 +6455,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -6463,7 +6463,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -6484,7 +6484,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -6500,7 +6500,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -6521,7 +6521,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -6537,7 +6537,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -6558,7 +6558,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -6566,7 +6566,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -6587,7 +6587,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -6595,7 +6595,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -6616,7 +6616,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -6624,7 +6624,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -6645,7 +6645,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -6653,7 +6653,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -6666,7 +6666,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -6674,7 +6674,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -6695,7 +6695,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -6703,7 +6703,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -6724,7 +6724,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -6732,7 +6732,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -6753,7 +6753,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -6761,7 +6761,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -6782,7 +6782,7 @@ def test_search_with_company_public_response__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -6844,7 +6844,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -6865,7 +6865,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -6873,7 +6873,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -6894,7 +6894,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -6902,7 +6902,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -6923,7 +6923,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -6939,7 +6939,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -6960,7 +6960,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -6976,7 +6976,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -6997,7 +6997,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -7005,7 +7005,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -7026,7 +7026,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -7034,7 +7034,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -7055,7 +7055,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -7063,7 +7063,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -7084,7 +7084,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -7092,7 +7092,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -7113,7 +7113,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -7121,7 +7121,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -7142,7 +7142,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -7150,7 +7150,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -7163,7 +7163,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -7171,7 +7171,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -7192,7 +7192,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -7200,7 +7200,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -7221,7 +7221,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -7283,7 +7283,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -7304,7 +7304,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -7312,7 +7312,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -7333,7 +7333,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -7341,7 +7341,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -7362,7 +7362,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -7378,7 +7378,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -7399,7 +7399,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -7415,7 +7415,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -7436,7 +7436,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -7444,7 +7444,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -7465,7 +7465,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -7473,7 +7473,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -7494,7 +7494,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -7502,7 +7502,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -7523,7 +7523,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -7531,7 +7531,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -7552,7 +7552,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -7560,7 +7560,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -7581,7 +7581,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -7589,7 +7589,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -7610,7 +7610,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -7618,7 +7618,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -7639,7 +7639,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -7647,7 +7647,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -7660,7 +7660,7 @@ def test_search_with_submitted_via__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -7722,7 +7722,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -7743,7 +7743,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -7751,7 +7751,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -7772,7 +7772,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -7780,7 +7780,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -7801,7 +7801,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -7817,7 +7817,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -7838,7 +7838,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -7854,7 +7854,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -7875,7 +7875,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -7883,7 +7883,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -7904,7 +7904,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -7912,7 +7912,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -7933,7 +7933,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -7941,7 +7941,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -7962,7 +7962,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -7970,7 +7970,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -7991,7 +7991,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -7999,7 +7999,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -8020,7 +8020,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -8028,7 +8028,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -8049,7 +8049,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -8057,7 +8057,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -8070,7 +8070,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -8078,7 +8078,7 @@ def test_search_with_tag__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -8099,7 +8099,7 @@ def test_search_with_tag__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -8161,7 +8161,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -8182,7 +8182,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -8190,7 +8190,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -8211,7 +8211,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -8219,7 +8219,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -8240,7 +8240,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -8256,7 +8256,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -8277,7 +8277,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -8293,7 +8293,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -8314,7 +8314,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -8322,7 +8322,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -8343,7 +8343,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -8351,7 +8351,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -8372,7 +8372,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -8380,7 +8380,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -8401,7 +8401,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -8409,7 +8409,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -8430,7 +8430,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -8438,7 +8438,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -8451,7 +8451,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -8459,7 +8459,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -8480,7 +8480,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -8488,7 +8488,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -8509,7 +8509,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -8517,7 +8517,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -8538,7 +8538,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 @@ -8600,7 +8600,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "filter": { "and": { "filters": [ @@ -8613,7 +8613,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Only show complaints with narratives?": { + "has_narratives": { "terms": { "field": "has_narratives", "size": 10 @@ -8621,7 +8621,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Matched company name": { + "company": { "filter": { "and": { "filters": [ @@ -8642,7 +8642,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Matched company name": { + "company": { "terms": { "field": "company", "size": 10000 @@ -8650,7 +8650,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Product / Subproduct": { + "product": { "filter": { "and": { "filters": [ @@ -8671,7 +8671,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Product / Subproduct": { + "product": { "terms": { "field": "product.raw", "size": 10000 @@ -8687,7 +8687,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Issue / Subissue": { + "issue": { "filter": { "and": { "filters": [ @@ -8708,7 +8708,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Issue / Subissue": { + "issue": { "terms": { "field": "issue.raw", "size": 10000 @@ -8724,7 +8724,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "State": { + "state": { "filter": { "and": { "filters": [ @@ -8745,7 +8745,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "State": { + "state": { "terms": { "field": "state", "size": 50 @@ -8753,7 +8753,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Zip code": { + "zip_code": { "filter": { "and": { "filters": [ @@ -8774,7 +8774,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Zip code": { + "zip_code": { "terms": { "field": "zip_code", "size": 1000 @@ -8782,7 +8782,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Did company provide a timely response?": { + "timely": { "filter": { "and": { "filters": [ @@ -8803,7 +8803,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Did company provide a timely response?": { + "timely": { "terms": { "field": "timely", "size": 10 @@ -8811,7 +8811,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Company response": { + "company_response": { "filter": { "and": { "filters": [ @@ -8832,7 +8832,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Company response": { + "company_response": { "terms": { "field": "company_response", "size": 100 @@ -8840,7 +8840,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Company public response": { + "company_public_response": { "filter": { "and": { "filters": [ @@ -8861,7 +8861,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Company public response": { + "company_public_response": { "terms": { "field": "company_public_response.raw", "size": 100 @@ -8869,7 +8869,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Did the consumer dispute the response?": { + "consumer_disputed": { "filter": { "and": { "filters": [ @@ -8890,7 +8890,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Did the consumer dispute the response?": { + "consumer_disputed": { "terms": { "field": "consumer_disputed", "size": 100 @@ -8898,7 +8898,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Consumer Consent": { + "consumer_consent_provided": { "filter": { "and": { "filters": [ @@ -8919,7 +8919,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Consumer Consent": { + "consumer_consent_provided": { "terms": { "field": "consumer_consent_provided.raw", "size": 100 @@ -8927,7 +8927,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "Tags": { + "tag": { "filter": { "and": { "filters": [ @@ -8948,7 +8948,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "Tags": { + "tag": { "terms": { "field": "tag", "size": 100 @@ -8956,7 +8956,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } } }, - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "filter": { "and": { "filters": [ @@ -8977,7 +8977,7 @@ def test_search_with_has_narratives__valid(self, mock_search): } }, "aggs": { - "How did the consumer submit the complaint to CFPB?": { + "submitted_via": { "terms": { "field": "submitted_via", "size": 100 From 4bb23b0ec235defab5af8edd25778d2589f634f8 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Thu, 29 Jun 2017 15:06:02 -0400 Subject: [PATCH 5/7] Break out test expected json objects in separate files --- .../search_no_param__valid.json | 314 + .../search_with_company__valid.json | 423 + ...h_with_company_public_response__valid.json | 421 + .../search_with_company_response__valid.json | 421 + ...with_consumer_consent_provided__valid.json | 421 + .../search_with_consumer_disputed__valid.json | 421 + .../search_with_field__valid.json | 315 + .../search_with_fmt_nonjson__valid.json | 314 + .../search_with_frm__valid.json | 314 + .../search_with_has_narratives__valid.json | 421 + .../search_with_issue__valid.json | 512 + .../search_with_max_date__valid.json | 352 + .../search_with_min_date__valid.json | 352 + .../search_with_product__valid.json | 527 + .../search_with_search_term__valid.json | 313 + .../search_with_size__valid.json | 314 + .../search_with_sort__valid.json | 313 + .../search_with_state__valid.json | 434 + .../search_with_submitted_via__valid.json | 421 + .../search_with_tag__valid.json | 421 + .../search_with_timely__valid.json | 421 + .../search_with_zip_code__valid.json | 434 + complaint_search/tests/test_es_interface.py | 8637 +---------------- 23 files changed, 8637 insertions(+), 8599 deletions(-) create mode 100644 complaint_search/tests/expected_results/search_no_param__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_company__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_company_public_response__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_company_response__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_field__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_frm__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_has_narratives__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_issue__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_max_date__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_min_date__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_product__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_search_term__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_size__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_sort__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_state__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_submitted_via__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_tag__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_timely__valid.json create mode 100644 complaint_search/tests/expected_results/search_with_zip_code__valid.json diff --git a/complaint_search/tests/expected_results/search_no_param__valid.json b/complaint_search/tests/expected_results/search_no_param__valid.json new file mode 100644 index 00000000..c85578a8 --- /dev/null +++ b/complaint_search/tests/expected_results/search_no_param__valid.json @@ -0,0 +1,314 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_company__valid.json b/complaint_search/tests/expected_results/search_with_company__valid.json new file mode 100644 index 00000000..531e3bf8 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_company__valid.json @@ -0,0 +1,423 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_company_public_response__valid.json b/complaint_search/tests/expected_results/search_with_company_public_response__valid.json new file mode 100644 index 00000000..d533ab50 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_company_public_response__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_company_response__valid.json b/complaint_search/tests/expected_results/search_with_company_response__valid.json new file mode 100644 index 00000000..8722d737 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_company_response__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json b/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json new file mode 100644 index 00000000..287dd135 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json b/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json new file mode 100644 index 00000000..88f869e4 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_field__valid.json b/complaint_search/tests/expected_results/search_with_field__valid.json new file mode 100644 index 00000000..c9c6548c --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_field__valid.json @@ -0,0 +1,315 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "test_field" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "test_field": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json b/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json new file mode 100644 index 00000000..c85578a8 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json @@ -0,0 +1,314 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_frm__valid.json b/complaint_search/tests/expected_results/search_with_frm__valid.json new file mode 100644 index 00000000..a1c9fb0c --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_frm__valid.json @@ -0,0 +1,314 @@ +{ + "from": 20, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_has_narratives__valid.json b/complaint_search/tests/expected_results/search_with_has_narratives__valid.json new file mode 100644 index 00000000..90e2bb86 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_has_narratives__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_issue__valid.json b/complaint_search/tests/expected_results/search_with_issue__valid.json new file mode 100644 index 00000000..501c53ce --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_issue__valid.json @@ -0,0 +1,512 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_max_date__valid.json b/complaint_search/tests/expected_results/search_with_max_date__valid.json new file mode 100644 index 00000000..005f5308 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_max_date__valid.json @@ -0,0 +1,352 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_min_date__valid.json b/complaint_search/tests/expected_results/search_with_min_date__valid.json new file mode 100644 index 00000000..11e9f717 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_min_date__valid.json @@ -0,0 +1,352 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_product__valid.json b/complaint_search/tests/expected_results/search_with_product__valid.json new file mode 100644 index 00000000..1a25df02 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_product__valid.json @@ -0,0 +1,527 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_search_term__valid.json b/complaint_search/tests/expected_results/search_with_search_term__valid.json new file mode 100644 index 00000000..7de09fe0 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_search_term__valid.json @@ -0,0 +1,313 @@ +{ + "from": 0, + "size": 10, + "query": { + "match": { + "complaint_what_happened": { + "query": "test_term", + "operator": "and" + } + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_size__valid.json b/complaint_search/tests/expected_results/search_with_size__valid.json new file mode 100644 index 00000000..c6bdedd8 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_size__valid.json @@ -0,0 +1,314 @@ +{ + "from": 0, + "size": 40, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_sort__valid.json b/complaint_search/tests/expected_results/search_with_sort__valid.json new file mode 100644 index 00000000..98bd6dc8 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_sort__valid.json @@ -0,0 +1,313 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_state__valid.json b/complaint_search/tests/expected_results/search_with_state__valid.json new file mode 100644 index 00000000..755ebe5d --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_state__valid.json @@ -0,0 +1,434 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_submitted_via__valid.json b/complaint_search/tests/expected_results/search_with_submitted_via__valid.json new file mode 100644 index 00000000..af7a0b22 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_submitted_via__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_tag__valid.json b/complaint_search/tests/expected_results/search_with_tag__valid.json new file mode 100644 index 00000000..33e85c54 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_tag__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_timely__valid.json b/complaint_search/tests/expected_results/search_with_timely__valid.json new file mode 100644 index 00000000..98f2cc68 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_timely__valid.json @@ -0,0 +1,421 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file 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 new file mode 100644 index 00000000..b0fceba9 --- /dev/null +++ b/complaint_search/tests/expected_results/search_with_zip_code__valid.json @@ -0,0 +1,434 @@ +{ + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "has_narratives": { + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "company": { + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "product": { + "terms": { + "field": "product.raw", + "size": 10000 + }, + "aggs": { + "sub_product.raw": { + "terms": { + "field": "sub_product.raw", + "size": 10000 + } + } + } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 + }, + "aggs": { + "sub_issue.raw": { + "terms": { + "field": "sub_issue.raw", + "size": 10000 + } + } + } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 + } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 + } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 + } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 + } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 + } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 + } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 + } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 + } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 + } + } + } + } + + } + } \ No newline at end of file diff --git a/complaint_search/tests/test_es_interface.py b/complaint_search/tests/test_es_interface.py index 7caf6c16..b3cc3296 100644 --- a/complaint_search/tests/test_es_interface.py +++ b/complaint_search/tests/test_es_interface.py @@ -9,6 +9,22 @@ import mock class EsInterfaceTest(TestCase): + # ------------------------------------------------------------------------- + # Helper Methods + # ------------------------------------------------------------------------- + + def to_absolute(self, fileName): + import os.path + # where is this module? + thisDir = os.path.dirname(__file__) + return os.path.join(thisDir, "expected_results", fileName) + + def load(self, shortName): + import json + fileName = self.to_absolute(shortName + '.json') + with open(fileName, 'r') as f: + return json.load(f) + def setUp(self): pass @@ -17,320 +33,7 @@ def setUp(self): @mock.patch('requests.get', ok=True, content="RGET_OK") def test_search_no_param__valid(self, mock_rget, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_no_param__valid") res = search() self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -353,320 +56,7 @@ def test_search_no_param__valid(self, mock_rget, mock_search): def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_rget, mock_search): mock_search.return_value = 'OK' mock_jdump.return_value = 'JDUMPS_OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_fmt_nonjson__valid") for fmt in ["csv", "xls", "xlsx"]: res = search(fmt=fmt) self.assertEqual(len(mock_jdump.call_args), 2) @@ -692,321 +82,7 @@ def test_search_with_fmt_nonjson__valid(self, mock_urlencode, mock_jdump, mock_r @mock.patch.object(Elasticsearch, 'search') def test_search_with_field__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "test_field" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "test_field": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - - } + body = self.load("search_with_field__valid") res = search(field="test_field") self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -1029,320 +105,7 @@ def test_search_with_fmt__invalid(self, mock_rget, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_size__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 40, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_size__valid") res = search(size=40) mock_search.assert_called_once_with(body=body, index="INDEX") @@ -1352,320 +115,7 @@ def test_search_with_size__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_frm__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 20, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_frm__valid") res = search(frm=20) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -1680,319 +130,7 @@ def test_search_with_frm__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_sort__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_sort__valid") sort_fields = [ ("relevance_desc", "_score", "desc"), @@ -2012,319 +150,7 @@ def test_search_with_sort__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_search_term__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "match": { - "complaint_what_happened": { - "query": "test_term", - "operator": "and" - } - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_search_term__valid") res = search(search_term="test_term") self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -2338,358 +164,7 @@ def test_search_with_search_term__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_min_date__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_min_date__valid") res = search(min_date="2014-04-14") self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -2703,358 +178,7 @@ def test_search_with_min_date__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_max_date__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_max_date__valid") res = search(max_date="2017-04-14") self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -3068,429 +192,7 @@ def test_search_with_max_date__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_company__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [ - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_company__valid") res = search(company=["Bank 1", "Second Bank"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -3510,533 +212,7 @@ def test_search_with_company__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_product__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [ - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_product__valid") res = search(product=["Payday Loan", u"Mortgage\u2022FHA Mortgage"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -4055,518 +231,7 @@ def test_search_with_product__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_issue__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_issue__valid") res = search(issue=[u"Communication tactics\u2022Frequent or repeated calls", "Loan servicing, payments, escrow account"]) self.assertEqual(len(mock_search.call_args), 2) @@ -4590,440 +255,7 @@ def test_search_with_issue__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_state__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_state__valid") res = search(state=["CA", "VA", "OR"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -5042,440 +274,7 @@ def test_search_with_state__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_zip_code__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_zip_code__valid") res = search(zip_code=["12345", "23435", "03433"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -5494,427 +293,7 @@ def test_search_with_zip_code__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_timely__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_timely__valid") res = search(timely=["Yes", "No"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -5933,427 +312,7 @@ def test_search_with_timely__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_company_response__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_company_response__valid") res = search(company_response=["Closed", "No response"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -6372,427 +331,7 @@ def test_search_with_company_response__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_company_public_response__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_company_public_response__valid") res = search(company_public_response=["Response 1", "Response 2"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -6811,427 +350,7 @@ def test_search_with_company_public_response__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_consumer_consent_provided__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_consumer_consent_provided__valid") res = search(consumer_consent_provided=["yes", "no"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -7250,427 +369,7 @@ def test_search_with_consumer_consent_provided__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_submitted_via__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_submitted_via__valid") res = search(submitted_via=["mail", "web"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -7689,427 +388,7 @@ def test_search_with_submitted_via__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_tag__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_tag__valid") res = search(tag=["Older American", "Servicemember"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -8128,427 +407,7 @@ def test_search_with_tag__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_consumer_disputed__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_consumer_disputed__valid") res = search(consumer_disputed=["No", "Yes"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) @@ -8567,427 +426,7 @@ def test_search_with_consumer_disputed__valid(self, mock_search): @mock.patch.object(Elasticsearch, 'search') def test_search_with_has_narratives__valid(self, mock_search): mock_search.return_value = 'OK' - body = { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" - } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { - "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - }] - } - }, - "aggs": { - "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 - } - } - } - }, - "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 - } - } - } - }, - "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "product": { - "terms": { - "field": "product.raw", - "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } - } - } - } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "issue": { - "terms": { - "field": "issue.raw", - "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } - } - } - } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 - } - } - } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 - } - } - } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 - } - } - } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 - } - } - } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 - } - } - } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 - } - } - } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 - } - } - } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 - } - } - } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 - } - } - } - } - - } - } + body = self.load("search_with_has_narratives__valid") res = search(has_narratives=["No", "Yes"]) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(0, len(mock_search.call_args[0])) From 81d0bfef674ed5335d01c27eeca100b87bf12196 Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Thu, 29 Jun 2017 17:17:59 -0400 Subject: [PATCH 6/7] Fix indentation --- .gitignore | 3 +- .../search_no_param__valid.json | 518 +++++----- .../search_with_company__valid.json | 712 +++++++------- ...h_with_company_public_response__valid.json | 726 +++++++------- .../search_with_company_response__valid.json | 726 +++++++------- ...with_consumer_consent_provided__valid.json | 726 +++++++------- .../search_with_consumer_disputed__valid.json | 726 +++++++------- .../search_with_field__valid.json | 518 +++++----- .../search_with_fmt_nonjson__valid.json | 518 +++++----- .../search_with_frm__valid.json | 518 +++++----- .../search_with_has_narratives__valid.json | 726 +++++++------- .../search_with_issue__valid.json | 910 +++++++++--------- .../search_with_max_date__valid.json | 548 +++++------ .../search_with_min_date__valid.json | 548 +++++------ .../search_with_product__valid.json | 860 ++++++++--------- .../search_with_search_term__valid.json | 516 +++++----- .../search_with_size__valid.json | 518 +++++----- .../search_with_sort__valid.json | 516 +++++----- .../search_with_state__valid.json | 752 +++++++-------- .../search_with_submitted_via__valid.json | 726 +++++++------- .../search_with_tag__valid.json | 726 +++++++------- .../search_with_timely__valid.json | 726 +++++++------- .../search_with_zip_code__valid.json | 752 +++++++-------- 23 files changed, 7258 insertions(+), 7257 deletions(-) diff --git a/.gitignore b/.gitignore index 09d9fd56..060c8f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env *.pyc db.sqlite3 -.coverage \ No newline at end of file +.coverage +.DS_Store \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_no_param__valid.json b/complaint_search/tests/expected_results/search_no_param__valid.json index c85578a8..6203ca12 100644 --- a/complaint_search/tests/expected_results/search_no_param__valid.json +++ b/complaint_search/tests/expected_results/search_no_param__valid.json @@ -1,314 +1,314 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file 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 531e3bf8..dccf4413 100644 --- a/complaint_search/tests/expected_results/search_with_company__valid.json +++ b/complaint_search/tests/expected_results/search_with_company__valid.json @@ -1,26 +1,47 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { "filters": [ + { + "range": { + "date_received": {} + } + }, { "bool": { "should": [ @@ -34,390 +55,369 @@ }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company": ["Bank 1"]}}, - {"terms": {"company": ["Second Bank"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company": ["Bank 1"]}}, + {"terms": {"company": ["Second Bank"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_company_public_response__valid.json b/complaint_search/tests/expected_results/search_with_company_public_response__valid.json index d533ab50..a559e744 100644 --- a/complaint_search/tests/expected_results/search_with_company_public_response__valid.json +++ b/complaint_search/tests/expected_results/search_with_company_public_response__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_public_response.raw": ["Response 1"]}}, - {"terms": {"company_public_response.raw": ["Response 2"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_public_response.raw": ["Response 1"]}}, + {"terms": {"company_public_response.raw": ["Response 2"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_company_response__valid.json b/complaint_search/tests/expected_results/search_with_company_response__valid.json index 8722d737..f66ad3d8 100644 --- a/complaint_search/tests/expected_results/search_with_company_response__valid.json +++ b/complaint_search/tests/expected_results/search_with_company_response__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"company_response": ["Closed"]}}, - {"terms": {"company_response": ["No response"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"company_response": ["Closed"]}}, + {"terms": {"company_response": ["No response"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json b/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json index 287dd135..74a30e22 100644 --- a/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json +++ b/complaint_search/tests/expected_results/search_with_consumer_consent_provided__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_consent_provided.raw": ["yes"]}}, - {"terms": {"consumer_consent_provided.raw": ["no"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_consent_provided.raw": ["yes"]}}, + {"terms": {"consumer_consent_provided.raw": ["no"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json b/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json index 88f869e4..5272cb4e 100644 --- a/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json +++ b/complaint_search/tests/expected_results/search_with_consumer_disputed__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"consumer_disputed": [0]}}, - {"terms": {"consumer_disputed": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"consumer_disputed": [0]}}, + {"terms": {"consumer_disputed": [1]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_field__valid.json b/complaint_search/tests/expected_results/search_with_field__valid.json index c9c6548c..45251787 100644 --- a/complaint_search/tests/expected_results/search_with_field__valid.json +++ b/complaint_search/tests/expected_results/search_with_field__valid.json @@ -1,315 +1,315 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "test_field" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "test_field" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "test_field": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "test_field": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } + } + + } - } \ No newline at end of file +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json b/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json index c85578a8..6203ca12 100644 --- a/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json +++ b/complaint_search/tests/expected_results/search_with_fmt_nonjson__valid.json @@ -1,314 +1,314 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_frm__valid.json b/complaint_search/tests/expected_results/search_with_frm__valid.json index a1c9fb0c..b3346d36 100644 --- a/complaint_search/tests/expected_results/search_with_frm__valid.json +++ b/complaint_search/tests/expected_results/search_with_frm__valid.json @@ -1,314 +1,314 @@ { - "from": 20, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 20, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_has_narratives__valid.json b/complaint_search/tests/expected_results/search_with_has_narratives__valid.json index 90e2bb86..c69a239f 100644 --- a/complaint_search/tests/expected_results/search_with_has_narratives__valid.json +++ b/complaint_search/tests/expected_results/search_with_has_narratives__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"has_narratives": [0]}}, - {"terms": {"has_narratives": [1]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"has_narratives": [0]}}, + {"terms": {"has_narratives": [1]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_issue__valid.json b/complaint_search/tests/expected_results/search_with_issue__valid.json index 501c53ce..2310ec58 100644 --- a/complaint_search/tests/expected_results/search_with_issue__valid.json +++ b/complaint_search/tests/expected_results/search_with_issue__valid.json @@ -1,512 +1,512 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - { - "and": { - "filters": [ - {"terms": {"issue.raw": ["Communication tactics"]}}, - {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} - ] - } - }, - {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } - } + }, + { + "bool": { + "should": [ + { + "and": { + "filters": [ + {"terms": {"issue.raw": ["Communication tactics"]}}, + {"terms": {"sub_issue.raw": ["Frequent or repeated calls"]}} + ] + } + }, + {"terms": {"issue.raw": ["Loan servicing, payments, escrow account"]}} + ] + } + } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_max_date__valid.json b/complaint_search/tests/expected_results/search_with_max_date__valid.json index 005f5308..ccda41ef 100644 --- a/complaint_search/tests/expected_results/search_with_max_date__valid.json +++ b/complaint_search/tests/expected_results/search_with_max_date__valid.json @@ -1,24 +1,39 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" + } + } } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { "filters": [ { @@ -33,320 +48,305 @@ }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "to": "2017-04-14" - } - } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "to": "2017-04-14" } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_min_date__valid.json b/complaint_search/tests/expected_results/search_with_min_date__valid.json index 11e9f717..f837337a 100644 --- a/complaint_search/tests/expected_results/search_with_min_date__valid.json +++ b/complaint_search/tests/expected_results/search_with_min_date__valid.json @@ -1,24 +1,39 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" + } + } } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { "filters": [ { @@ -33,320 +48,305 @@ }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": { - "from": "2014-04-14" - } - } + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": { + "from": "2014-04-14" } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_product__valid.json b/complaint_search/tests/expected_results/search_with_product__valid.json index 1a25df02..805f90e8 100644 --- a/complaint_search/tests/expected_results/search_with_product__valid.json +++ b/complaint_search/tests/expected_results/search_with_product__valid.json @@ -1,26 +1,55 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [ + { + "bool": { + "should": [ + + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } + } + ] + } } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + ] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { "filters": [ + { + "range": { + "date_received": {} + } + }, { "bool": { "should": [ @@ -42,486 +71,457 @@ }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ - {"terms": {"product.raw": ["Payday Loan"]}}, - { - "and": { - "filters": [ - {"terms": {"product.raw": ["Mortgage"]}}, - {"terms": {"sub_product.raw": ["FHA Mortgage"]}} - ] - } - } - ] + {"terms": {"product.raw": ["Payday Loan"]}}, + { + "and": { + "filters": [ + {"terms": {"product.raw": ["Mortgage"]}}, + {"terms": {"sub_product.raw": ["FHA Mortgage"]}} + ] + } } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_search_term__valid.json b/complaint_search/tests/expected_results/search_with_search_term__valid.json index 7de09fe0..ccff66cd 100644 --- a/complaint_search/tests/expected_results/search_with_search_term__valid.json +++ b/complaint_search/tests/expected_results/search_with_search_term__valid.json @@ -1,313 +1,313 @@ { - "from": 0, - "size": 10, - "query": { - "match": { - "complaint_what_happened": { - "query": "test_term", - "operator": "and" - } + "from": 0, + "size": 10, + "query": { + "match": { + "complaint_what_happened": { + "query": "test_term", + "operator": "and" + } + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_size__valid.json b/complaint_search/tests/expected_results/search_with_size__valid.json index c6bdedd8..aa9b1f3b 100644 --- a/complaint_search/tests/expected_results/search_with_size__valid.json +++ b/complaint_search/tests/expected_results/search_with_size__valid.json @@ -1,314 +1,314 @@ { - "from": 0, - "size": 40, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 40, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_sort__valid.json b/complaint_search/tests/expected_results/search_with_sort__valid.json index 98bd6dc8..036fbe0e 100644 --- a/complaint_search/tests/expected_results/search_with_sort__valid.json +++ b/complaint_search/tests/expected_results/search_with_sort__valid.json @@ -1,313 +1,313 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "post_filter": {"and": {"filters": []}}, + "aggs": { + "has_narratives": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + } + ] } }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "post_filter": {"and": {"filters": []}}, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_state__valid.json b/complaint_search/tests/expected_results/search_with_state__valid.json index 755ebe5d..80b75da6 100644 --- a/complaint_search/tests/expected_results/search_with_state__valid.json +++ b/complaint_search/tests/expected_results/search_with_state__valid.json @@ -1,434 +1,434 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"state": ["CA"]}}, - {"terms": {"state": ["VA"]}}, - {"terms": {"state": ["OR"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"state": ["CA"]}}, + {"terms": {"state": ["VA"]}}, + {"terms": {"state": ["OR"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_submitted_via__valid.json b/complaint_search/tests/expected_results/search_with_submitted_via__valid.json index af7a0b22..0012d9f5 100644 --- a/complaint_search/tests/expected_results/search_with_submitted_via__valid.json +++ b/complaint_search/tests/expected_results/search_with_submitted_via__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"submitted_via": ["mail"]}}, - {"terms": {"submitted_via": ["web"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"submitted_via": ["mail"]}}, + {"terms": {"submitted_via": ["web"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_tag__valid.json b/complaint_search/tests/expected_results/search_with_tag__valid.json index 33e85c54..5749c1ab 100644 --- a/complaint_search/tests/expected_results/search_with_tag__valid.json +++ b/complaint_search/tests/expected_results/search_with_tag__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"tag": ["Older American"]}}, - {"terms": {"tag": ["Servicemember"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"tag": ["Older American"]}}, + {"terms": {"tag": ["Servicemember"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file diff --git a/complaint_search/tests/expected_results/search_with_timely__valid.json b/complaint_search/tests/expected_results/search_with_timely__valid.json index 98f2cc68..e6253e7f 100644 --- a/complaint_search/tests/expected_results/search_with_timely__valid.json +++ b/complaint_search/tests/expected_results/search_with_timely__valid.json @@ -1,421 +1,421 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"timely": ["Yes"]}}, - {"terms": {"timely": ["No"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"timely": ["Yes"]}}, + {"terms": {"timely": ["No"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file 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 b0fceba9..973cfde1 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 @@ -1,434 +1,434 @@ { - "from": 0, - "size": 10, - "query": { - "query_string": { - "query": "*", - "fields": [ - "complaint_what_happened" - ], - "default_operator": "AND" + "from": 0, + "size": 10, + "query": { + "query_string": { + "query": "*", + "fields": [ + "complaint_what_happened" + ], + "default_operator": "AND" + } + }, + "highlight": { + "fields": { + "complaint_what_happened": {} + }, + "number_of_fragments": 1, + "fragment_size": 500 + }, + "sort": [{"_score": {"order": "desc"}}], + "post_filter": { + "and": { + "filters": [{ + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } - }, - "highlight": { - "fields": { - "complaint_what_happened": {} - }, - "number_of_fragments": 1, - "fragment_size": 500 - }, - "sort": [{"_score": {"order": "desc"}}], - "post_filter": { + }] + } + }, + "aggs": { + "has_narratives": { + "filter": { "and": { - "filters": [{ - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } } - }] + ] } }, "aggs": { "has_narratives": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "has_narratives": { - "terms": { - "field": "has_narratives", - "size": 10 + "terms": { + "field": "has_narratives", + "size": 10 + } + } + } + }, + "company": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "company": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company": { - "terms": { - "field": "company", - "size": 10000 + "terms": { + "field": "company", + "size": 10000 + } + } + } + }, + "product": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } - } - }, + ] + } + }, + "aggs": { "product": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } + "terms": { + "field": "product.raw", + "size": 10000 }, "aggs": { - "product": { + "sub_product.raw": { "terms": { - "field": "product.raw", + "field": "sub_product.raw", "size": 10000 - }, - "aggs": { - "sub_product.raw": { - "terms": { - "field": "sub_product.raw", - "size": 10000 - } - } } } } - }, - "issue": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] + } + } + }, + "issue": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] + } } + ] + } + }, + "aggs": { + "issue": { + "terms": { + "field": "issue.raw", + "size": 10000 }, "aggs": { - "issue": { + "sub_issue.raw": { "terms": { - "field": "issue.raw", + "field": "sub_issue.raw", "size": 10000 - }, - "aggs": { - "sub_issue.raw": { - "terms": { - "field": "sub_issue.raw", - "size": 10000 - } - } } } } - }, - "state": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "state": { - "terms": { - "field": "state", - "size": 50 + } + } + }, + "state": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "state": { + "terms": { + "field": "state", + "size": 50 } - }, - "zip_code": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - } - ] - } - }, - "aggs": { - "zip_code": { - "terms": { - "field": "zip_code", - "size": 1000 + } + } + }, + "zip_code": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} } } + ] + } + }, + "aggs": { + "zip_code": { + "terms": { + "field": "zip_code", + "size": 1000 } - }, - "timely": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "timely": { - "terms": { - "field": "timely", - "size": 10 + } + } + }, + "timely": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "timely": { + "terms": { + "field": "timely", + "size": 10 } - }, - "company_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_response": { - "terms": { - "field": "company_response", - "size": 100 + } + } + }, + "company_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "company_response": { + "terms": { + "field": "company_response", + "size": 100 } - }, - "company_public_response": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "company_public_response": { - "terms": { - "field": "company_public_response.raw", - "size": 100 + } + } + }, + "company_public_response": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "company_public_response": { + "terms": { + "field": "company_public_response.raw", + "size": 100 } - }, - "consumer_disputed": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_disputed": { - "terms": { - "field": "consumer_disputed", - "size": 100 + } + } + }, + "consumer_disputed": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_disputed": { + "terms": { + "field": "consumer_disputed", + "size": 100 } - }, - "consumer_consent_provided": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "consumer_consent_provided": { - "terms": { - "field": "consumer_consent_provided.raw", - "size": 100 + } + } + }, + "consumer_consent_provided": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "consumer_consent_provided": { + "terms": { + "field": "consumer_consent_provided.raw", + "size": 100 } - }, - "tag": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "tag": { - "terms": { - "field": "tag", - "size": 100 + } + } + }, + "tag": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "tag": { + "terms": { + "field": "tag", + "size": 100 } - }, - "submitted_via": { - "filter": { - "and": { - "filters": [ - { - "range": { - "date_received": {} - } - }, - { - "bool": { - "should": [ - {"terms": {"zip_code": ["12345"]}}, - {"terms": {"zip_code": ["23435"]}}, - {"terms": {"zip_code": ["03433"]}} - ] - } - } - ] - } - }, - "aggs": { - "submitted_via": { - "terms": { - "field": "submitted_via", - "size": 100 + } + } + }, + "submitted_via": { + "filter": { + "and": { + "filters": [ + { + "range": { + "date_received": {} + } + }, + { + "bool": { + "should": [ + {"terms": {"zip_code": ["12345"]}}, + {"terms": {"zip_code": ["23435"]}}, + {"terms": {"zip_code": ["03433"]}} + ] } } + ] + } + }, + "aggs": { + "submitted_via": { + "terms": { + "field": "submitted_via", + "size": 100 } } - } - } \ No newline at end of file + } + + } +} \ No newline at end of file From 4a01a3c76e6122a9d789900b307081449237892b Mon Sep 17 00:00:00 2001 From: Amy Mok Date: Thu, 29 Jun 2017 17:26:58 -0400 Subject: [PATCH 7/7] Remove incorrect info --- complaint_search/es_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/complaint_search/es_interface.py b/complaint_search/es_interface.py index 2b1db47f..0c28585f 100644 --- a/complaint_search/es_interface.py +++ b/complaint_search/es_interface.py @@ -254,7 +254,7 @@ def search(**kwargs): # post-filter body["post_filter"] = {"and": {"filters": []}} - ## Create base aggregation (without filters at this point) + ## Create base aggregation body["aggs"] = _create_aggregation(**kwargs) ## date