Beispiel #1
0
def test_search_query_combines_query():
    s = Search()

    s2 = s.query("match", f=42)
    assert s2._query.to_dict() == Query(Match(f=42)).to_dict()
    assert s._query.to_dict() is None

    s3 = s2.query("match", f=43)
    assert s2._query.to_dict() == Query(Match(f=42)).to_dict()
    assert ordered(s3._query.to_dict()) == ordered(
        Query(Bool(must=[Match(f=42), Match(f=43)])).to_dict())
Beispiel #2
0
    def test_search_query_combines_query(self):
        s = Search()

        s2 = s.query("match", f=42)
        self.assertEqual(s2._query.to_dict(), Query(Match(f=42)).to_dict())
        self.assertEqual(s._query.to_dict(), None)

        s3 = s2.query("match", f=43)
        self.assertEqual(s2._query.to_dict(), Query(Match(f=42)).to_dict())
        self.assertEqual(
            ordered(s3._query.to_dict()),
            ordered(Query(Bool(must=[Match(f=42), Match(f=43)])).to_dict()),
        )
Beispiel #3
0
    def test_search_to_dict(self):
        s = Search()
        assert {} == s.to_dict()

        s = s.query("match", f=42)
        assert {"query": {"match": {"f": {"query": 42}}}} == s.to_dict()

        assert {
            "query": {
                "match": {
                    "f": {
                        "query": 42
                    }
                }
            },
            "size": 10
        } == s.to_dict(size=10)

        s = s.aggs("per_tag", "terms", field="f").aggs("max_score",
                                                       "max",
                                                       field="score")
        d = {
            "aggs": {
                "per_tag": {
                    "terms": {
                        "field": "f"
                    },
                    "aggs": {
                        "max_score": {
                            "max": {
                                "field": "score"
                            }
                        }
                    },
                }
            },
            "query": {
                "match": {
                    "f": {
                        "query": 42
                    }
                }
            },
        }
        self.assertEqual(d, s.to_dict())

        s = Search().params(size=5)
        assert {"size": 5} == s.to_dict()
        s = s.params(from_=42)
        assert {"size": 5, "from": 42} == s.to_dict()
Beispiel #4
0
 def test_query_always_returns_search(self):
     s = Search()
     self.assertIsInstance(s.query("match", f=42), Search)
Beispiel #5
0
def test_query_always_returns_search():
    s = Search()
    assert isinstance(s.query("match", f=42), Search)