示例#1
0
    def test_nested_aggregation(self):
        agg = Nested("resellers", "resellers")
        agg.add_aggregation(Min("min_price").set_field("price"))

        query = Query()
        query.add_aggregation(agg)
        results = self._index.search(query).aggregations['resellers']

        self.assertEqual(4.98, results['min_price']['value'])
示例#2
0
 def test_to_dict(self):
     expected = {
         "min": {
             "field": "price",
             "script": "_value * conversion_rate",
             "params": {
                 "conversion_rate": 1.2
             }
         }
     }
     agg = Min("min_price_in_euros")
     agg.set_field("price")
     agg.set_script(Script("_value * conversion_rate", {"conversion_rate": 1.2}))
     self.assertEqual(expected, agg.to_dict())
示例#3
0
    def test_min_aggregation(self):
        agg = Min("min_price")
        agg.set_field("price")

        query = Query()
        query.add_aggregation(agg)
        results = self._index.get_doc_type("test").search(query).aggregations["min_price"]
        self.assertAlmostEqual(1, results["value"])

        # test using a script
        agg.set_script(Script("_value * conversion_rate", {"conversion_rate": 1.2}))
        query = Query()
        query.add_aggregation(agg)
        results = self._index.get_doc_type("test").search(query).aggregations["min_price"]
        self.assertEqual(1.2, results["value"])