def test_suggest_accepts_global_text(self): s = Search.from_dict({ "suggest": { "text": "the amsterdma meetpu", "my-suggest-1": { "term": { "field": "title" } }, "my-suggest-2": { "text": "other", "term": { "field": "body" } }, } }) assert { "suggest": { "my-suggest-1": { "term": { "field": "title" }, "text": "the amsterdma meetpu", }, "my-suggest-2": { "term": { "field": "body" }, "text": "other" }, } } == s.to_dict()
def test_from_dict_doesnt_need_query(self): s = Search.from_dict({"size": 5}) assert {"size": 5} == s.to_dict()
def test_reverse(self): d = { "aggs": { "per_country": { "aggs": { "avg_attendees": { "avg": { "field": "attendees" } } }, "terms": { "field": "country" }, } }, "highlight": { "fields": { "title": { "fragment_size": 50 } }, "order": "score" }, "post_filter": { "bool": { "must": [{ "terms": { "tags": ["prague", "czech"] } }] } }, "query": { "bool": { "filter": [{ "bool": { "should": [ { "term": { "category": { "value": "meetup" } } }, { "term": { "category": { "value": "conference" } } }, ] } }], "must": [{ "bool": { "minimum_should_match": 2, "must": [{ "match": { "title": { "query": "python" } } }], "must_not": [{ "match": { "title": { "query": "ruby" } } }], } }], } }, "script_fields": { "more_attendees": { "script": "doc['attendees'].value + 42" } }, "size": 5, "sort": ["title", { "category": { "order": "desc" } }, "_score"], "suggest": { "my-title-suggestions-1": { "term": { "field": "title", "size": 3 }, "text": "devloping distibutd saerch " "engies", } }, } d2 = deepcopy(d) s = Search.from_dict(d) # make sure we haven't modified anything in place self.assertEqual(d, d2) self.assertSearchEqual(d, s.to_dict())