Ejemplo n.º 1
0
def test_metric_inside_buckets():
    a = aggs.Terms(field="tags")
    b = a.metric("max_score", "max", field="score")

    # returns bucket so it's chainable
    assert a is b
    assert a.aggs["max_score"] == aggs.Max(field="score")
Ejemplo n.º 2
0
def test_metric_inside_buckets():
    a = aggs.Terms(field='tags')
    b = a.metric('max_score', 'max', field='score')

    # returns bucket so it's chainable
    assert a is b
    assert a.aggs['max_score'] == aggs.Max(field='score')
Ejemplo n.º 3
0
def test_A_handles_nested_aggs_properly():
    max_score = aggs.Max('max_score', field='score')
    a = aggs.A('per_tag', 'terms', field='tags', aggs={'max_score': max_score})

    assert isinstance(a, aggs.Terms)
    assert a._params == {'field': 'tags', 'aggs': {'max_score': max_score}}
    assert a._name == 'per_tag'
Ejemplo n.º 4
0
def test_aggregate_inside_buckets():
    a = aggs.Terms('per_tag', field='tags')
    b = a.aggregate('max_score', 'max', field='score')

    # returns bucket so it's chainable
    assert a is b
    assert a.aggs['max_score'] == aggs.Max('max_score', field='score')
Ejemplo n.º 5
0
def test_meta_from_dict():
    max_score = aggs.Max(field="score")
    a = aggs.A(
        "terms", field="tags", aggs={"max_score": max_score}, meta={"some": "metadata"}
    )

    assert aggs.A(a.to_dict()) == a
Ejemplo n.º 6
0
def test_meta_from_dict():
    max_score = aggs.Max(field='score')
    a = aggs.A('terms',
               field='tags',
               aggs={'max_score': max_score},
               meta={'some': 'metadata'})

    assert aggs.A(a.to_dict()) == a
Ejemplo n.º 7
0
def test_meta():
    max_score = aggs.Max(field="score")
    a = aggs.A(
        "terms", field="tags", aggs={"max_score": max_score}, meta={"some": "metadata"}
    )

    assert {
        "terms": {"field": "tags"},
        "aggs": {"max_score": {"max": {"field": "score"}}},
        "meta": {"some": "metadata"},
    } == a.to_dict()
Ejemplo n.º 8
0
def test_meta():
    max_score = aggs.Max(field='score')
    a = aggs.A('terms',
               field='tags',
               aggs={'max_score': max_score},
               meta={'some': 'metadata'})

    assert {
        'terms': {
            'field': 'tags'
        },
        'aggs': {
            'max_score': {
                'max': {
                    'field': 'score'
                }
            }
        },
        'meta': {
            'some': 'metadata'
        }
    } == a.to_dict()
Ejemplo n.º 9
0
def test_A_handles_nested_aggs_properly():
    max_score = aggs.Max(field="score")
    a = aggs.A("terms", field="tags", aggs={"max_score": max_score})

    assert isinstance(a, aggs.Terms)
    assert a._params == {"field": "tags", "aggs": {"max_score": max_score}}
Ejemplo n.º 10
0
def test_repr():
    max_score = aggs.Max(field="score")
    a = aggs.A("terms", field="tags", aggs={"max_score": max_score})

    assert "Terms(aggs={'max_score': Max(field='score')}, field='tags')" == repr(
        a)
Ejemplo n.º 11
0
def test_repr():
    max_score = aggs.Max(field='score')
    a = aggs.A('terms', field='tags', aggs={'max_score': max_score})

    assert "Terms(aggs={'max_score': Max(field='score')}, field='tags')" == repr(
        a)
Ejemplo n.º 12
0
 def add_agg_date_min_max(self, search: Search) -> Search:
     search = copy(search)
     search.aggs.metric("min_date", aggs.Min(field=self._date_field))
     search.aggs.metric("max_date", aggs.Max(field=self._date_field))
     return search