def test_zero_clauses(): """No condition is given so a match_all query should be generated """ request = DummyRequest() filter_json = { 'clauses': [], } fef = FilterToElasticFilter(filter_json, request) assert fef.query['query']['filtered']['query'] == {"match_all": {}}
def test_policy_include_any(): request = DummyRequest() filter_json = { 'match_policy': 'include_any', 'clauses': [{ 'field': 'text', 'operator': 'equals', 'value': 'foo', 'options': {} }, { 'field': 'tag', 'operator': 'equals', 'value': 'bar', 'options': {} }], } fef = FilterToElasticFilter(filter_json, request) assert 'should' in fef.query['query']['filtered']['query']['bool']
def test_operator_call(): request = DummyRequest() filter_json = { 'match_policy': 'include_all', 'clauses': [{ 'field': '/text', 'operator': 'equals', 'value': 'foo bar', 'options': { 'es': { 'query_type': 'simple' } } }], } generated = FilterToElasticFilter(filter_json, request) query = generated.query['query']['filtered']['query']['bool']['must'][0] expected = 'foo bar' assert query['term']['text'] == expected