Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._filter = {'range': {dim: {'gte': value}}}
class Greater(Filter):
def __init__(self, dim, value):
super(Greater, self).__init__()
self._filter = {'range': {dim: {'gt': value}}}
class LessEqual(Filter):
def __init__(self, dim, value):
super(LessEqual, self).__init__()
self._filter = {'range': {dim: {'lte': value}}}
class Less(Filter):
def __init__(self, dim, value):
super(Less, self).__init__()
self._filter = {'range': {dim: {'lt': value}}}
class Equal(Filter):
def __init__(self, dim, value):
super(Equal, self).__init__()
self._filter = {'term': {dim: value}}
class IsIn(Filter):
def __init__(self, dim, value):
super(IsIn, self).__init__()
assert isinstance(value, list)
self._filter = {'terms': {dim: value}}
def build(self):
return self._filter
def debug_string(self, indent=4):
return json.dumps(self._filter, indent=indent)
# Binary operator
class And(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(And, self).__init__()
self._filter = {'bool': {'must': [x.build() for x in args]}}
class Or(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(Or, self).__init__()
self._filter = {'bool': {'should': [x.build() for x in args]}}
class Not(Filter):
def __init__(self, x):
assert isinstance(x, Filter)
super(Not, self).__init__()
self._filter = {'bool': {'must_not': x.build()}}
# Leaves
class GreaterEqual(Filter):
def __init__(self, dim, value):
class Or(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(Or, self).__init__()
self._filter = {'bool': {'should': [x.build() for x in args]}}
class Not(Filter):
def __init__(self, x):
assert isinstance(x, Filter)
super(Not, self).__init__()
self._filter = {'bool': {'must_not': x.build()}}
# Leaves
class GreaterEqual(Filter):
def __init__(self, dim, value):
super(GreaterEqual, self).__init__()
self._filter = {'range': {dim: {'gte': value}}}
class Greater(Filter):
def __init__(self, dim, value):
super(Greater, self).__init__()
self._filter = {'range': {dim: {'gt': value}}}
class LessEqual(Filter):
def __init__(self, dim, value):
super(LessEqual, self).__init__()
self._filter = {'range': {dim: {'lte': value}}}
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(Or, self).__init__()
self._filter = {'bool': {'should': [x.build() for x in args]}}
@property
def subtree(self):
if 'bool' in self._filter:
return self._filter['bool']
else:
return self._filter
def build(self):
return self._filter
def debug_string(self, indent=4):
return json.dumps(self._filter, indent=indent)
# Binary operator
class And(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(And, self).__init__()
self._filter = {'bool': {'must': [x.build() for x in args]}}
class Or(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(Or, self).__init__()
self._filter = {'bool': {'should': [x.build() for x in args]}}
class Not(Filter):
def __init__(self, x):
assert isinstance(x, Filter)
class Not(Filter):
def __init__(self, x):
assert isinstance(x, Filter)
super(Not, self).__init__()
self._filter = {'bool': {'must_not': x.build()}}
# Leaves
class GreaterEqual(Filter):
def __init__(self, dim, value):
super(GreaterEqual, self).__init__()
self._filter = {'range': {dim: {'gte': value}}}
class Greater(Filter):
def __init__(self, dim, value):
super(Greater, self).__init__()
self._filter = {'range': {dim: {'gt': value}}}
class LessEqual(Filter):
def __init__(self, dim, value):
super(LessEqual, self).__init__()
self._filter = {'range': {dim: {'lte': value}}}
class Less(Filter):
def __init__(self, dim, value):
super(Less, self).__init__()
self._filter = {'range': {dim: {'lt': value}}}
self._filter = {'range': {dim: {'lte': value}}}
class Less(Filter):
def __init__(self, dim, value):
super(Less, self).__init__()
self._filter = {'range': {dim: {'lt': value}}}
class Equal(Filter):
def __init__(self, dim, value):
super(Equal, self).__init__()
self._filter = {'term': {dim: value}}
class IsIn(Filter):
def __init__(self, dim, value):
super(IsIn, self).__init__()
assert isinstance(value, list)
self._filter = {'terms': {dim: value}}
def _build_query(self, aggs=None, filter=None, size=None):
query = {}
if aggs is not None and len(aggs) > 0:
agg_dict = {}
for agg in aggs:
assert isinstance(agg, Aggregator)
agg_dict.update(agg.build())
query['aggregations'] = agg_dict
if filter is not None:
assert isinstance(filter, Filter)
query['query'] = {'filtered': {'filter': filter.build()}}
else:
query['query'] = {"match_all": {}}
if size is not None:
query['size'] = size
self._last_query = query
return query
self._filter = {'range': {dim: {'gt': value}}}
class LessEqual(Filter):
def __init__(self, dim, value):
super(LessEqual, self).__init__()
self._filter = {'range': {dim: {'lte': value}}}
class Less(Filter):
def __init__(self, dim, value):
super(Less, self).__init__()
self._filter = {'range': {dim: {'lt': value}}}
class Equal(Filter):
def __init__(self, dim, value):
super(Equal, self).__init__()
self._filter = {'term': {dim: value}}
class IsIn(Filter):
def __init__(self, dim, value):
super(IsIn, self).__init__()
assert isinstance(value, list)
self._filter = {'terms': {dim: value}}
# Binary operator
class And(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(And, self).__init__()
self._filter = {'bool': {'must': [x.build() for x in args]}}
class Or(Filter):
def __init__(self, *args):
[isinstance(x, Filter) for x in args]
super(Or, self).__init__()
self._filter = {'bool': {'should': [x.build() for x in args]}}
class Not(Filter):
def __init__(self, x):
assert isinstance(x, Filter)
super(Not, self).__init__()
self._filter = {'bool': {'must_not': x.build()}}
# Leaves
class GreaterEqual(Filter):
def __init__(self, dim, value):
super(GreaterEqual, self).__init__()
self._filter = {'range': {dim: {'gte': value}}}
class Greater(Filter):
def __init__(self, dim, value):
super(Greater, self).__init__()