def common_event_topics(num_topics=10, num_contracts=10, only_sigs=False):
    """This query aggregates the most common event signatures and their most common contract
    addresses.

    Usage:
        es.search('ethereum', 'log', body=common_event_topics())

    Params:
        num_topics (int): maximum number of topics to collect
        num_contracts (int): maximum number of contract addresses per topic
        only_sigs (bool): if true, only collect `topic0`
    Returns:
        query (dict): an elasticsearch query body dictionary.
    """
    return {
        "query": {
            "match_all": {}
        },
        "aggs": {
            "topic": {
                "terms": {
                    "field": "signature" if only_sigs else "topics",
                    "size": num_topics
                },
                "aggs": {
                    "contract": {
                        "terms": {
                            "field": "address",
                            "size": num_contracts
                        }
                    }
                }
            }
        },
        "size": 0
    }