def METHOD_NAME(self, quantity, op, value, nested=None):
    """
    Return a range, match, or term query for the given quantity, comparison
    operator, and value
    """
    field = self._field(quantity, nested=nested)
    if op in self.operator_map:
        return Q("range", **{field: {self.operator_map[op]: value}})
    if quantity.elastic_mapping_type == 'text':
        query_type = "match"
    elif quantity.elastic_mapping_type in ['keyword', 'integer', 'float', 'bool']:
        query_type = "term"
    else:
        raise NotImplementedError("Quantity has unsupported ES field type")
    if op in ["=", ""]:
        return Q(query_type, **{field: value})
    if op == "!=":
        return ~Q(  # pylint: disable=invalid-unary-operand-type
            query_type, **{field: value}
        )