def query_es_for_accounts_by_battles(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    accounts_per_battles_range_query['query']['bool']['must'][(- 1)]['range']['date']['gt'] = then.strftime('%Y-%m-%d')
    accounts_per_battles_range_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    if ('battle ranges' in config):
        accounts_per_battles_range_query['aggs']['2']['range']['ranges'] = config['battle ranges']
    response = es.search(index=config['battle index'], body=accounts_per_battles_range_query)
    buckets = {'xbox': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys())), 'ps': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys())), 'all': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys()))}
    for (key, value) in response['aggregations']['2']['buckets'].items():
        buckets['all'][key] = value['doc_count']
        for bucket in value['3']['buckets']:
            buckets[bucket['key']][key] = bucket['doc_count']
    return buckets
def query_es_for_accounts_by_battles(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    accounts_per_battles_range_query['query']['bool']['must'][(- 1)]['range']['date']['gt'] = then.strftime('%Y-%m-%d')
    accounts_per_battles_range_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    if ('battle ranges' in config):
        accounts_per_battles_range_query['aggs']['2']['range']['ranges'] = config['battle ranges']
    response = es.search(index=config['battle index'], body=accounts_per_battles_range_query)
    buckets = {'xbox': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys())), 'ps': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys())), 'all': OrderedDict(((v, 0) for v in response['aggregations']['2']['buckets'].keys()))}
    for (key, value) in response['aggregations']['2']['buckets'].items():
        buckets['all'][key] = value['doc_count']
        for bucket in value['3']['buckets']:
            buckets[bucket['key']][key] = bucket['doc_count']
    return buckets