• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.add_document函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.helpers.add_document函数的典型用法代码示例。如果您正苦于以下问题:Python add_document函数的具体用法?Python add_document怎么用?Python add_document使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_search_with_iterator

def test_search_with_iterator(context):
    """
    Search using an iterator
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And set iterator fetching to a small size
    t._per_request = 2

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

    # And I do a filter on my new object

    # And a different filter on my old object
    t.order_by(Sort("bar", order="asc"))

    # Then I get the expected results
    for (counter, result) in enumerate(t):
        result['_source'].should.equal({"bar": counter})

    len(t).should.equal(5)
    t.count().should.equal(5)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:28,代码来源:test_queryset.py


示例2: test_search_multiple_scoring

def test_search_multiple_scoring(context):
    """
    Search with custom scoring and params
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

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

    # And I add scoring with params
    score = ScriptScore("s = custom_param + doc['bar'].value", params={"custom_param": 1})
    t.score(score)

    boost = {
        "boost_factor": "10",
        "filter": Exists("baz")
    }
    t.score(boost)
    results = t[0:10]

    # Then my results are scored correctly
    len(results).should.equal(2)
    results[0]["_source"]["baz"].should.equal(4)
    ("baz" in results[1]["_source"].keys()).should.be.false
开发者ID:Yipit,项目名称:pyeqs,代码行数:26,代码来源:test_score.py


示例3: test_search_nested_terms_aggregations_with_size

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,代码行数:25,代码来源:test_aggregations.py


示例4: test_search_with_filter_and_scoring_and_sorting_and_fields

def test_search_with_filter_and_scoring_and_sorting_and_fields(context):
    """
    Search with match_all query, filter, scoring, sorting, and fields
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz", "scoring_field": 0, "sorting_field": 30})
    add_document("foo", {"bar": "baz", "scoring_field": 1, "sorting_field": 20})
    add_document("foo", {"bar": "baz", "scoring_field": 2, "sorting_field": 10})
    add_document("foo", {"bar": "bazbaz", "scoring_field": 3, "sorting_field": 0})

    # And I do a search
    t.filter(Term("bar", "baz"))
    score = ScriptScore("final_score = 0 + doc['scoring_field'].value;")
    t.score(score)
    sorting = Sort("sorting_field", order="desc")
    t.order_by(sorting)
    t.only(["bar"])
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(3)
    results[0]['fields'].should.equal({"bar": ["baz"]})
    results[1]['fields'].should.equal({"bar": ["baz"]})
    results[2]['fields'].should.equal({"bar": ["baz"]})
开发者ID:jpatel3,项目名称:pyeqs,代码行数:27,代码来源:test_queryset.py


示例5: test_query_string

def test_query_string(context):
    """
    Search with query string
    """
    # When I create a queryset with a query string
    qs = QueryString("cheese")
    t = QuerySet("localhost", index="foo", query=qs)

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

    # Then I get a the expected results
    results = t[0:10]
    len(results).should.equal(1)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:15,代码来源:test_query_string.py


示例6: test_query_string_with_additional_parameters

def test_query_string_with_additional_parameters(context):
    """
    Search with query string and additional parameters
    """
    # When I create a queryset with parameters
    qs = QueryString("cheese", fields=["bar"], use_dis_max=False, tie_breaker=0.05)
    t = QuerySet("localhost", index="foo", query=qs)

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

    # Then I get a the expected results
    results = t[0:10]
    len(results).should.equal(1)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:15,代码来源:test_query_string.py


示例7: test_simple_search

def test_simple_search(context):
    """
    Search with match_all query
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I do a search
    results = t[0:1]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "baz"})
开发者ID:jpatel3,项目名称:pyeqs,代码行数:16,代码来源:test_queryset.py


示例8: test_string_search

def test_string_search(context):
    """
    Search with string query
    """
    # When create a queryset
    t = QuerySet("localhost", query="cheese", index="foo")

    # And there are records
    add_document("foo", {"bar": "banana"})
    add_document("foo", {"bar": "cheese"})

    # And I do a search
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "cheese"})
开发者ID:jpatel3,项目名称:pyeqs,代码行数:17,代码来源:test_queryset.py


示例9: test_geo_distance_search_with_field_name

def test_geo_distance_search_with_field_name(context):
    """
    Search with geo distance filter with field_name
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"foo_loc": {"lat": 1.1, "lon": 2.1}})
    add_document("foo", {"foo_loc": {"lat": 40.1, "lon": 80.1}})

    # And I filter for distance
    t.filter(GeoDistance({"lat": 1.0, "lon": 2.0}, "20mi", field_name="foo_loc"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
开发者ID:Yipit,项目名称:pyeqs,代码行数:17,代码来源:test_geo_distance.py


示例10: test_search_nested_aggregations

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,代码行数:17,代码来源:test_aggregations.py


示例11: test_geo_distance_search_array

def test_geo_distance_search_array(context):
    """
    Search with geo distance filter with array
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"location": {"lat": 1.1, "lon": 2.1}})
    add_document("foo", {"location": {"lat": 40.1, "lon": 80.1}})

    # And I filter for terms
    t.filter(GeoDistance([2.0, 1.0], "20mi"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
开发者ID:mengjues,项目名称:pyeqs,代码行数:17,代码来源:test_geo_distance.py


示例12: test_simple_search_with_host_list

def test_simple_search_with_host_list(context):
    """
    Connect with host list
    """
    # When create a queryset
    connection_info = [{"host": "localhost", "port": 9200}]
    t = QuerySet(connection_info, index="foo")

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

    # And I do a search
    results = t[0:1]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "baz"})
开发者ID:Yipit,项目名称:pyeqs,代码行数:17,代码来源:test_connection.py


示例13: test_simple_search_with_filter

def test_simple_search_with_filter(context):
    """
    Search with filter
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I do a filtered search
    t.filter(Term("bar", "baz"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "baz"})
开发者ID:Yipit,项目名称:pyeqs,代码行数:18,代码来源:test_filters.py


示例14: test_terms_search_with_execution

def test_terms_search_with_execution(context):
    """
    Search with terms filter with execution
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I filter for terms
    t.filter(Terms("foo", ["foo", "bar"], execution="and"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]["_source"]["foo"].should.equal(["foo", "bar"])
开发者ID:Yipit,项目名称:pyeqs,代码行数:18,代码来源:test_terms.py


示例15: test_search_with_exists

def test_search_with_exists(context):
    """
    Search with exists filter
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

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

    # And I add an exists filter
    exists = Exists("baz")
    t.filter(exists)
    results = t[0:10]

    # Then my results only have that field
    len(results).should.equal(1)
    results[0]["_source"]["baz"].should.equal(1)
开发者ID:Yipit,项目名称:pyeqs,代码行数:19,代码来源:test_exists.py


示例16: test_search_aggregation

def test_search_aggregation(context):
    """
    Search with aggregation
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I do an aggregated search
    t.aggregate(aggregation=Aggregations("foo_attrs", "bar", "terms"))
    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': 1}, {u'key': u'bazbaz', u'doc_count': 1}])
开发者ID:Yipit,项目名称:pyeqs,代码行数:19,代码来源:test_aggregations.py


示例17: test_wrappers

def test_wrappers(context):
    """
    Search with wrapped match_all query
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I do a search
    def wrapper_function(search_results):
        return map(lambda x: x["_source"]["bar"] + 1, search_results)

    t.wrappers(wrapper_function)
    t.order_by(Sort("bar", order="asc"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(3)
    results[0].should.equal(2)
    results[1].should.equal(3)
    results[2].should.equal(4)
开发者ID:sunchen009,项目名称:pyeqs,代码行数:25,代码来源:test_queryset.py


示例18: test_search_global_aggregations

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,代码行数:26,代码来源:test_aggregations.py


示例19: test_post_query_actions

def test_post_query_actions(context):
    """
    Search with match_all query with post query actions
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I have a post query action
    global my_global_var
    my_global_var = 1

    def action(self, results, start, stop):
        global my_global_var
        my_global_var += 1

    t.post_query_actions(action)

    # And I do a search
    t.order_by(Sort("bar", order="asc"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(3)
    results[0]["_source"]["bar"].should.equal(1)
    results[1]["_source"]["bar"].should.equal(2)
    results[2]["_source"]["bar"].should.equal(3)
    my_global_var.should.equal(2)
开发者ID:Yipit,项目名称:pyeqs,代码行数:32,代码来源:test_queryset.py


示例20: test_search_as_queryset_with_filter

def test_search_as_queryset_with_filter(context):
    """
    Search with match_all query and filter on a cloned queryset
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

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

    # And I do a filter on my new object
    my_search = t.objects.filter(Term("bar", "baz"))

    # And a different filter on my old object
    t.filter(Term("bar", "bazbaz"))

    # And I do a search
    results = my_search[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "baz"})
开发者ID:jpatel3,项目名称:pyeqs,代码行数:23,代码来源:test_queryset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.assert_equals函数代码示例发布时间:2022-05-27
下一篇:
Python helper.TestHelper类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap