Skip to content

Commit

Permalink
Merge pull request #15 from amymok/meta
Browse files Browse the repository at this point in the history
Add meta information
  • Loading branch information
amymok authored Jul 12, 2017
2 parents beac47a + 05aef30 commit 23aa99d
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 186 deletions.
1 change: 1 addition & 0 deletions complaint_search/es_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def build(self):
Field('tag', 100, False),
Field('submitted_via', 100, False)
]

aggs = {}

# Creating aggregation object for each field above
Expand Down
15 changes: 15 additions & 0 deletions complaint_search/es_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def get_es():
timeout=100)
return _ES_INSTANCE

def get_meta():
body = {
# size: 0 here to prevent taking too long since we only needed max_date
"size": 0,
"aggs": { "max_date" : { "max" : { "field" : "date_received" }}}
}
max_date_res = get_es().search(index=_COMPLAINT_ES_INDEX, body=body)
count_res = get_es().count(index=_COMPLAINT_ES_INDEX, doc_type=_COMPLAINT_DOC_TYPE)
return {
"license": "CC0",
"last_updated": max_date_res["aggregations"]["max_date"]["value_as_string"],
"total_record_count": count_res["count"]
}
# List of possible arguments:
# - format: format to be returned: "json", "csv", "xls", or "xlsx"
# - field: field you want to search in: "complaint_what_happened", "company_public_response", "_all"
Expand Down Expand Up @@ -65,6 +78,8 @@ def search(**kwargs):

res = get_es().search(index=_COMPLAINT_ES_INDEX, body=body)

res["_meta"] = get_meta()

elif format in ("csv", "xls", "xlsx"):
p = {"format": format, "source": json.dumps(body)}
p = urllib.urlencode(p)
Expand Down
Loading

0 comments on commit 23aa99d

Please sign in to comment.