Skip to content

Instantly share code, notes, and snippets.

@djw8605
Last active April 20, 2016 18:57
Show Gist options
  • Save djw8605/e3851fe055e6d41575cb3d005a62d240 to your computer and use it in GitHub Desktop.
Save djw8605/e3851fe055e6d41575cb3d005a62d240 to your computer and use it in GitHub Desktop.
Snippet to get the record counts from an ElasticSearch cluster
def GetCountRecords(client, from_date, to_date, query = None):
"""
Get the number of records (documents) from a date range
"""
s = Search(using=client, index='gracc-osg-*') \
.filter('range', **{'@timestamp': {'from': from_date, 'to': to_date}}) \
.params(search_type="count")
response = s.execute()
return response.hits.total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment