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


Python helpers.add_document函数代码示例

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


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


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