当前位置: 首页>>代码示例>>Python>>正文


Python QuerySet.aggregations方法代码示例

本文整理汇总了Python中pyeqs.QuerySet.aggregations方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.aggregations方法的具体用法?Python QuerySet.aggregations怎么用?Python QuerySet.aggregations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyeqs.QuerySet的用法示例。


在下文中一共展示了QuerySet.aggregations方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_search_terms_aggregation_with_order_two

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_terms_aggregation_with_order_two(context):
    """
    Search with terms aggregation ordered by count ascending
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "bazbaz"})
    add_document("foo", {"bar": "bazbaz"})
    add_document("foo", {"bar": "bazbar"})

    # And I do an aggregated search
    t.aggregate(aggregation=Aggregations("foo_attrs", "bar", "terms",
                                         order_type="_count", order_dir="asc"))
    t[0:10]

    # Then I get a the expected results
    t.aggregations().should.have.key('foo_attrs')

    t.aggregations()['foo_attrs'].should.have.key("buckets").being.equal([
        {u'key': u'bazbar', u'doc_count': 1},
        {u'key': u'bazbaz', u'doc_count': 2},
        {u'key': u'baz', u'doc_count': 3}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:29,代码来源:test_aggregations.py

示例2: test_search_global_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_global_aggregations(context):
    """
    Search with global aggregations
    """
    # With a specific query
    # q = QueryBuilder(query_string=QueryString(query={"match": {"foo_attr": "yes"}}))

    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz", "foo_attr": "yes"})
    add_document("foo", {"bar": "bazbaz", "foo_attr": "no"})
    add_document("foo", {"bar": "bazbaz"})

    # And I do a global
    t.aggregate(aggregation=Aggregations("foo_attrs", "bar", "terms", global_name="all_bar"))
    t[0:10]

    # I get the expected results
    t.aggregations().should.have.key("all_bar").being.equal({
        u'foo_attrs': {u'buckets': [
            {u'key': u'bazbaz', u'doc_count': 2},
            {u'key': u'baz', u'doc_count': 1}
        ]},
        u'doc_count': 3})
开发者ID:Yipit,项目名称:pyeqs,代码行数:28,代码来源:test_aggregations.py

示例3: test_search_histogram_aggregations_with_min_doc_count

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_histogram_aggregations_with_min_doc_count(context):
    """
    Search with aggregations that have histograms with min_doc_count
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 2})
    add_document("foo", {"bar": 3, "foo": "bazbaz"})
    add_document("foo", {"bar": 5, "foo": "foobar"})
    add_document("foo", {"bar": 5})
    add_document("foo", {"bar": 5, "foo": "foobaz"})
    add_document("foo", {"bar": 9})

    # When I do a histogram aggregation
    t.aggregate(aggregation=Aggregations("bar_buckets", "bar", "metric", histogram_interval=2,
                                         min_doc_count=2))
    t[0:10]

    # I get the expected results
    t.aggregations().should.have.key("bar_buckets")
    t.aggregations()["bar_buckets"].should.have.key("buckets").being.equal([
        {u'key': 4, u'doc_count': 3},
        {u'key': 2, u'doc_count': 2},
        {u'key': 0, u'doc_count': 2}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:30,代码来源:test_aggregations.py

示例4: test_search_nested_terms_aggregations_with_size

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_nested_terms_aggregations_with_size(context):
    """
    Search with nested terms aggregation and a specified size
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are nested records
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": "type0"}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": "type0"}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": "type1"}], "foo": "foofoo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": "type2"}], "foo": "foofoo"})

    # And I do a nested
    t.aggregate(aggregation=Aggregations("baz_types", "bazbaz", "terms",
                                         nested_path="child", size=1))
    t[0:10]

    # The I get the expected results
    t.aggregations().should.have.key("child").being.equal({
        u'baz_types': {
            u'buckets': [{u'doc_count': 2, u'key': u'type0'}]
        },
        u'doc_count': 4
    })
开发者ID:Yipit,项目名称:pyeqs,代码行数:27,代码来源:test_aggregations.py

示例5: test_search_nested_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_nested_aggregations(context):
    """
    Search with nested aggregations
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are nested records
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": 10}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": 1}], "foo": "foofoo"})

    # And I do a nested
    t.aggregate(aggregation=Aggregations("best_bazbaz", "bazbaz", "max", nested_path="child"))
    t[0:10]

    # The I get the expected results
    t.aggregations().should.have.key("child").being.equal({'best_bazbaz': {'value': 10.0}, 'doc_count': 2})
开发者ID:Yipit,项目名称:pyeqs,代码行数:19,代码来源:test_aggregations.py

示例6: test_search_terms_aggregation_with_size

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_terms_aggregation_with_size(context):
    """
    Search with terms aggregation w/ specified size
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "bazbaz"})
    add_document("foo", {"bar": "bazbar"})

    # And I do an aggregated search
    t.aggregate(aggregation=Aggregations("foo_attrs", "bar", "terms", size=1))
    t[0:10]

    # Then I get a the expected results
    t.aggregations().should.have.key('foo_attrs')
    t.aggregations()['foo_attrs'].should.have.key("buckets").being.equal([
        {u'key': u'baz', u'doc_count': 2}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:23,代码来源:test_aggregations.py

示例7: test_search_filtered_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_filtered_aggregations(context):
    """
    Search with filtered aggregations
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 2})
    add_document("foo", {"bar": 3, "foo": "bazbaz"})
    add_document("foo", {"bar": 5, "foo": "foobar"})
    add_document("foo", {"bar": 5})
    add_document("foo", {"bar": 5, "foo": "foobaz"})
    add_document("foo", {"bar": 9})

    # And I do a filtered
    f = Filter().filter(Range("bar", gte=5))
    t.aggregate(aggregation=Aggregations("missing_foo", "foo", "missing",
                                         filter_val=f, filter_name="high_bar"))
    t[0:10]

    # Then I get the expected results
    t.aggregations().should.have.key("high_bar")
    t.aggregations()["high_bar"].should.have.key("missing_foo").being.equal(
        {u'doc_count': 2})
    t.aggregations()["high_bar"]["doc_count"].should.equal(4)
开发者ID:Yipit,项目名称:pyeqs,代码行数:30,代码来源:test_aggregations.py

示例8: test_queryset_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_queryset_aggregations():
    """
    Fetch aggregation data from QuerySet with #aggregations
    """
    # When I create a query block
    t = QuerySet("localhost", index="bar")

    # And I aggregate something
    a = Aggregations("agg_name", "field_name", "metric")
    t.aggregate(a)

    # And I have records
    response = {
        "took": 12,
        "hits": {
            "total": 1,
            "max_score": 10,
            "hits": [
                {"_index": "bar",
                 "_type": "baz",
                 "_id": "1",
                 "_score": 10,
                 "_source": {
                     "foo": "bar"
                 },
                 "sort": [
                     1395687078000
                 ]}
            ]
        },
        "aggregations": {
            "agg_name": {"metric": {"field": "field_name"}}
        }
    }
    httpretty.register_uri(httpretty.GET, "http://localhost:9200/bar/_search",
                           body=json.dumps(response),
                           content_type="application/json")

    t[0:1]
    t.aggregations().should.have.key("agg_name").being.equal({"metric": {"field": "field_name"}})
开发者ID:Yipit,项目名称:pyeqs,代码行数:42,代码来源:test_queryset.py

示例9: test_search_range_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_range_aggregations(context):
    """
    Search with aggregations for ranges
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": 1, "foo": "foo"})
    add_document("foo", {"bar": 2, "foo": "foo"})
    add_document("foo", {"bar": 2})

    # When I do a ranged aggregation
    range_list = [0, 1, 2, 3]
    t.aggregate(aggregation=Aggregations("bar_types", "bar", "metric", range_list=range_list))
    t[0:10]

    # I get the expected results
    t.aggregations().should.have.key("bar_ranges")
    t.aggregations()["bar_ranges"].should.have.key("buckets").being.equal([
        {u'to': 0.0, u'doc_count': 0},
        {u'to': 1.0, u'from': 0.0, u'doc_count': 0},
        {u'to': 2.0, u'from': 1.0, u'doc_count': 1},
        {u'to': 3.0, u'from': 2.0, u'doc_count': 2},
        {u'from': 3.0, u'doc_count': 0}])

    # And I should be able to name it if I want
    t.aggregate(aggregation=Aggregations("bar_types", "bar", "metric",
                                         range_list=range_list, range_name="my_unique_range"))
    t[0:10]

    # I get the expected results
    t.aggregations().should.have.key("my_unique_range")
    t.aggregations()["my_unique_range"].should.have.key("buckets").being.equal([
        {u'to': 0.0, u'doc_count': 0},
        {u'to': 1.0, u'from': 0.0, u'doc_count': 0},
        {u'to': 2.0, u'from': 1.0, u'doc_count': 1},
        {u'to': 3.0, u'from': 2.0, u'doc_count': 2},
        {u'from': 3.0, u'doc_count': 0}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:41,代码来源:test_aggregations.py

示例10: test_search_multi_aggregations

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import aggregations [as 别名]
def test_search_multi_aggregations(context):
    """
    Search with multiple aggregations
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz", "foo": "foo"})
    add_document("foo", {"bar": "bazbaz", "foo": "foo"})
    add_document("foo", {"bar": "bazbaz"})

    # And I do an aggregated search on two dimensions
    t.aggregate(aggregation=Aggregations("bar_attrs", "bar", "terms"))
    t.aggregate(aggregation=Aggregations("missing_foo", "foo", "missing"))
    t[0:10]

    # Then I get a the expected results
    t.aggregations().should.have.key("missing_foo").being.equal({u'doc_count': 1})
    t.aggregations().should.have.key("bar_attrs")
    t.aggregations()['bar_attrs'].should.have.key("buckets").being.equal([
        {u'key': u'bazbaz', u'doc_count': 2}, {u'key': u'baz', u'doc_count': 1}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:24,代码来源:test_aggregations.py


注:本文中的pyeqs.QuerySet.aggregations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。