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


Python Index.document方法代码示例

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


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

示例1: setup_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def setup_index(year):
    index = Index(f'{INDEX_NAME}-{year}')
    index.settings(number_of_shards=2, number_of_replicas=0)
    index.aliases(politicians={})
    index.document(Politicians)
    index.analyzer(brazilian_analyzer)
    index.create()
开发者ID:olhoneles,项目名称:politicos,代码行数:9,代码来源:models.py

示例2: test_index_can_be_created_with_settings_and_mappings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_index_can_be_created_with_settings_and_mappings(write_client):
    i = Index('test-blog', using=write_client)
    i.document(Post)
    i.settings(number_of_replicas=0, number_of_shards=1)
    i.create()

    assert {
        'test-blog': {
            'mappings': {
                'properties': {
                    'title': {'type': 'text', 'analyzer': 'my_analyzer'},
                    'published_from': {'type': 'date'}
                }
            }
        }
    } == write_client.indices.get_mapping(index='test-blog')

    settings = write_client.indices.get_settings(index='test-blog')
    assert settings['test-blog']['settings']['index']['number_of_replicas'] == '0'
    assert settings['test-blog']['settings']['index']['number_of_shards'] == '1'
    assert settings['test-blog']['settings']['index']['analysis'] == {
        'analyzer': {
            'my_analyzer': {
                'type': 'custom',
                'tokenizer': 'keyword'
            }
        }
    }
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:30,代码来源:test_index.py

示例3: test_registered_doc_type_included_in_search

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_registered_doc_type_included_in_search():
    i = Index('i', using='alias')
    i.document(Post)

    s = i.search()

    assert s._doc_type == [Post]
开发者ID:3lnc,项目名称:elasticsearch-dsl-py,代码行数:9,代码来源:test_index.py

示例4: test_registered_doc_type_included_in_to_dict

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_registered_doc_type_included_in_to_dict():
    i = Index('i', using='alias')
    i.document(Post)

    assert {
        'mappings': {
            'properties': {
                'title': {'type': 'text'},
                'published_from': {'type': 'date'},
            }
        }
    } == i.to_dict()
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:14,代码来源:test_index.py

示例5: test_conflicting_mapping_raises_error_in_index_to_dict

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_conflicting_mapping_raises_error_in_index_to_dict():
    class A(document.Document):
        name = field.Text()

    class B(document.Document):
        name = field.Keyword()

    i = Index('i')
    i.document(A)
    i.document(B)

    with raises(ValueError):
        i.to_dict()
开发者ID:3lnc,项目名称:elasticsearch-dsl-py,代码行数:15,代码来源:test_document.py

示例6: test_multiple_doc_types_will_combine_mappings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_multiple_doc_types_will_combine_mappings():
    class User(Document):
        username = Text()

    i = Index('i')
    i.document(Post)
    i.document(User)
    assert {
        'mappings': {
            'properties': {
                'title': {'type': 'text'},
                'username': {'type': 'text'},
                'published_from': {'type': 'date'}
            }
        }
    } == i.to_dict()
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:18,代码来源:test_index.py

示例7: test_conflicting_doc_types_cause_exception

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import document [as 别名]
def test_conflicting_doc_types_cause_exception():
    i = Index('i', doc_type='t')

    with raises(exceptions.IllegalOperation):
        i.document(Post)
开发者ID:3lnc,项目名称:elasticsearch-dsl-py,代码行数:7,代码来源:test_index.py


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