def termsFilter(fieldname):
    """
    Transforms a comma separated list of keywords into a terms query object,
    which can be used by an ES search operation.

    raises a ValueError of no valid keyword is provided.
    """
    def handleFilter(value):
        if isinstance(value, (list, tuple)):
            keys = [v.strip() for v in value if v.strip()]
        else:
            keys = [v.strip() for v in value.split(',') if v.strip()]
        if keys:
            return {"terms": {fieldname: keys}}
        raise ValueError("No keywords provided")
    return handleFilter