def generate_match_query(field, value, with_operator_and):
    """Helper for generating a match query.

    Args:
        field (six.text_type): The ES field to be queried.
        value (six.text_type/bool): The value of the query (bool for the case of type-code query ["core: true"]).
        with_operator_and (bool): Flag that signifies whether to generate the explicit notation of the query, along
            with '"operator": "and"', so that all tokens of the query value are required to match.

    Notes:
        If value is of instance bool, then the shortened version of the match query is generated, at all times.
    """
    parsed_value = None
    try:
        parsed_value = json.loads(value.lower())
    except (ValueError, TypeError, AttributeError):
        # Catch all possible exceptions
        # we are not interested if they will appear
        pass

    if isinstance(value, bool):
        return {'match': {field: value}}
    elif isinstance(parsed_value, bool):
        return {'match': {field: value.lower()}}

    if with_operator_and:
        return {
            'match': {
                field: {
                    'query': value,
                    'operator': 'and'
                }
            }
        }

    return {'match': {field: value}}
Helper for generating a match query.

    Args:
        field (six.text_type): The ES field to be queried.
        value (six.text_type/bool): The value of the query (bool for the case of type-code query ["core: true"]).
        with_operator_and (bool): Flag that signifies whether to generate the explicit notation of the query, along
            with '"operator": "and"', so that all tokens of the query value are required to match.

    Notes:
        If value is of instance bool, then the shortened version of the match query is generated, at all times.