def test_filters_correctly_identifies_the_hash(): a = aggs.A('filters', filters={ 'group_a': { 'term': { 'group': 'a' } }, 'group_b': { 'term': { 'group': 'b' } } }) assert { 'filters': { 'filters': { 'group_a': { 'term': { 'group': 'a' } }, 'group_b': { 'term': { 'group': 'b' } } } } } == a.to_dict() assert a.filters.group_a == filter.F('term', group='a')
def test_function_score_to_dict(): q = query.Q('function_score', query=query.Q('match', title='python'), functions=[ query.SF('random'), query.SF('field_value_factor', field='comment_count', filter=filter.F('term', tags='python')) ]) d = { 'function_score': { 'query': { 'match': { 'title': 'python' } }, 'functions': [{ 'random': {} }, { 'filter': { 'term': { 'tags': 'python' } }, 'field_value_factor': { 'field': 'comment_count', } }], } } assert d == q.to_dict()
def test_filter_aggregation_with_nested_aggs(): a = aggs.Filter(filter.F('term', f=42)) a.bucket('testing', 'terms', field='tags') assert { 'filter': { 'term': { 'f': 42 } }, 'aggs': { 'testing': { 'terms': { 'field': 'tags' } } } } == a.to_dict()
def test_filter_aggregation_as_nested_agg(): a = aggs.Terms(field='tags') a.bucket('filtered', 'filter', filter.F('term', f=42)) assert { 'terms': { 'field': 'tags' }, 'aggs': { 'filtered': { 'filter': { 'term': { 'f': 42 } }, } } } == a.to_dict()
def test_function_score_with_no_function_is_boost_factor(): q = query.Q( 'function_score', functions=[query.SF({ 'weight': 20, 'filter': filter.F('term', f=42) })]) assert { 'function_score': { 'functions': [{ 'filter': { 'term': { 'f': 42 } }, 'weight': 20 }] } } == q.to_dict()
def _get_colombia_filter(self): if self.allow_colombia and self.request.REGION == mkt.regions.COL: return None co_filter = es_filter.Term(tags=COLOMBIA_WEBSITE) return es_filter.F(es_filter.Bool(must_not=[co_filter]), )
def test_filter_can_be_instantiated_using_positional_args(): a = aggs.Filter(filter.F('term', f=42)) assert {'filter': {'term': {'f': 42}}} == a.to_dict() assert a == aggs.A('filter', filter.F('term', f=42))
def test_and_can_be_created_with_a_list(): f = filter.F('and', [filter.F('term', field='value')]) assert isinstance(f, filter.And) assert f.filters == [filter.F('term', field='value')] assert f == filter.And([filter.F('term', field='value')])
def test_query_can_use_positional_arg(): f = filter.F('query', Q('match_all')) assert f.query == Q('match_all') assert {'query': {'match_all': {}}} == f.to_dict()
def test_not_doesnt_have_to_wrap_filter(): f = filter.F('not', term={'field': 'value'}) assert isinstance(f, filter.Not) assert f.filter == filter.F('term', field='value') assert f == filter.Not(filter.F('term', field='value'))
def test_other_filters_must_use_kwargs(): with raises(ValueError): filter.F('bool', [filter.F('term', field='value')])
def test_repr(): f = filter.F('terms', **{'some.path': 'value'}) assert "Terms(some__path='value')" == repr(f)
def test_empty_F_is_match_all(): f = filter.F() assert isinstance(f, filter.MatchAll) assert filter.MatchAll() == f
def test_and_can_be_created_from_list(): f = filter.F({'and': [{'term': {'f': 'v'}}, {'term': {'f2': 42}}]}) assert f == filter.And([filter.F('term', f='v'), filter.F('term', f2=42)])