# Path: api/theatrics/connections.py

# 
# Path: api/theatrics/settings.py
# ELASTICSEARCH_INDEX = os.environ.get('ELASTICSEARCH_INDEX', 'theatrics')
# 
# Path: api/theatrics/utils/functional.py
# def containing(value):
#     return lambda container: value in container


import aioes
from funcy import collecting, compact, is_seqcont, pluck
from .connections import elastic
from .settings import ELASTICSEARCH_INDEX
from .utils.functional import containing
    took = response['took']
    count = hits['total']
    items = list(map(simplify_item, hits['hits']))
    return items, count, took


async def fetch_item(type_, id_, fields=None):
    kwargs = {}
    if fields:
        kwargs['_source'] = ','.join(fields)

    try:
        response = await elastic.get(ELASTICSEARCH_INDEX, id_, type_, **kwargs)
    except aioes.NotFoundError:
        return None
    else:
        return simplify_item(response)


async def fetch_multiple_items(type_, ids, fields=None):
    kwargs = {}
    if fields:
        kwargs['_source'] = ','.join(fields)

    response = await elastic.mget(
        {'ids': ids}, ELASTICSEARCH_INDEX, type_, **kwargs)
    return [simplify_item(doc) for doc in response['docs']]


async def expand_item(item, relations):

# Path: api/theatrics/connections.py

# 
# Path: api/theatrics/settings.py
# ELASTICSEARCH_INDEX = os.environ.get('ELASTICSEARCH_INDEX', 'theatrics')
# 
# Path: api/theatrics/utils/functional.py
# def containing(value):
#     return lambda container: value in container


# Path: api/theatrics/dao.py
import aioes
from funcy import collecting, compact, is_seqcont, pluck
from .connections import elastic
from .settings import ELASTICSEARCH_INDEX
from .utils.functional import containing

    took = response['took']
    count = hits['total']
    items = list(map(simplify_item, hits['hits']))
    return items, count, took


async def fetch_item(type_, id_, fields=None):
    kwargs = {}
    if fields:
        kwargs['_source'] = ','.join(fields)

    try:
        response = await elastic.get(ELASTICSEARCH_INDEX, id_, type_, **kwargs)
    except aioes.NotFoundError:
        return None
    else:
        return simplify_item(response)


async def fetch_multiple_items(type_, ids, fields=None):
    kwargs = {}
    if fields:
        kwargs['_source'] = ','.join(fields)

    response = await elastic.mget(
        {'ids': ids}, ELASTICSEARCH_INDEX, type_, **kwargs)
    return [simplify_item(doc) for doc in response['docs']]


async def expand_item(item, relations):

    return (await expand_multiple_items([item], relations))[0]