def es_filter_cases(domain, filters=None):
    q = ElasticCaseQuery(domain, filters)
    meta = ES_META['cases']
    res = get_es_new().search(meta.index, body=q.get_query())
    # this is ugly, but for consistency / ease of deployment just
    # use this to return everything in the expected format for now
    return [CommCareCase.wrap(r["_source"]) for r in res['hits']['hits'] if r["_source"]]
Filter cases using elastic search
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cloudcare/api.py/es_filter_cases