Ejemplo n.º 1
0
    def test_max_aggregation(self):
        agg = Max("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(8, 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(8 * 1.2, results["value"])
Ejemplo n.º 2
0
 def test_to_dict(self):
     expected = {
         "max": {
             "field": "price",
             "script": "_value * conversion_rate",
             "params": {
                 "conversion_rate": 1.2
             }
         },
         "aggs": {
             "subagg": {"max": {"field": "foo"}}
         }
     }
     agg = Max("min_price_in_euros")
     agg.set_field("price")
     agg.set_script(Script("_value * conversion_rate", {"conversion_rate": 1.2}))
     agg.add_aggregation(Max("subagg").set_field("foo"))
     self.assertEqual(expected, agg.to_dict())