當前位置: 首頁>>代碼示例>>Python>>正文


Python elasticsearch_dsl.Document方法代碼示例

本文整理匯總了Python中elasticsearch_dsl.Document方法的典型用法代碼示例。如果您正苦於以下問題:Python elasticsearch_dsl.Document方法的具體用法?Python elasticsearch_dsl.Document怎麽用?Python elasticsearch_dsl.Document使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在elasticsearch_dsl的用法示例。


在下文中一共展示了elasticsearch_dsl.Document方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_doctype

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def create_doctype(index_name, similarity):
    if similarity == 'default':
        wiki_content_field = Text()
        qb_content_field = Text()
    else:
        wiki_content_field = Text(similarity=similarity)
        qb_content_field = Text(similarity=similarity)

    class Answer(Document):
        page = Text(fields={'raw': Keyword()})
        wiki_content = wiki_content_field
        qb_content = qb_content_field

        class Meta:
            index = index_name

    return Answer 
開發者ID:Pinafore,項目名稱:qb,代碼行數:19,代碼來源:elasticsearch.py

示例2: test_multiple_doc_types_will_combine_mappings

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl 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

示例3: __init__

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def __init__(self):
        """Perform initial checks and save given object."""
        class_name = type(self).__name__
        if not self.object_type:
            raise RuntimeError("`object_type` must be defined in {}".format(class_name))

        if not self.document_class:
            raise RuntimeError(
                "`document_class` must be defined in {}".format(class_name)
            )

        if self.queryset is None:
            raise RuntimeError("`queryset` must be defined in {}".format(class_name))

        # Apply any extensions defined for the given document class. Document class extensions
        # come in the form of field definitions.
        self.document_class = copy.deepcopy(self.document_class)
        for extension in composer.get_extensions(self.document_class):
            for name in dir(extension):
                field = getattr(extension, name)
                if isinstance(field, dsl.Field):
                    self.document_class._doc_type.mapping.field(name, field)

        #: list of built documents waiting to be pushed
        self.push_queue = []

        self._index_name = self.document_class()._get_index()
        self._mapping_created = False

        #: id of thread id where connection was established
        self.connection_thread_id = None 
開發者ID:genialis,項目名稱:resolwe,代碼行數:33,代碼來源:indices.py

示例4: test_bucket_keys_get_deserialized

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def test_bucket_keys_get_deserialized(aggs_data, aggs_search):
    class Commit(Document):
        info = Object(properties={'committed_date': Date()})

        class Index:
            name = 'test-commit'

    aggs_search = aggs_search.doc_type(Commit)
    agg_response = response.Response(aggs_search, aggs_data)

    per_month = agg_response.aggregations.per_month
    for b in per_month:
        assert isinstance(b.key, date) 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:15,代碼來源:test_result.py

示例5: test_required_int_can_be_0

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def test_required_int_can_be_0():
    class DT(Document):
        i = Integer(required=True)

    dt = DT(i=0)
    assert dt.full_clean() is None 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:8,代碼來源:test_validation.py

示例6: test_required_field_cannot_be_empty_list

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def test_required_field_cannot_be_empty_list():
    class DT(Document):
        i = Integer(required=True)

    dt = DT(i=[])
    with raises(ValidationException):
        dt.full_clean() 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:9,代碼來源:test_validation.py

示例7: test_validation_works_for_lists_of_values

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def test_validation_works_for_lists_of_values():
    class DT(Document):
        i = Date(required=True)

    dt = DT(i=[datetime.now(), 'not date'])
    with raises(ValidationException):
        dt.full_clean()

    dt = DT(i=[datetime.now(), datetime.now()])
    assert None is dt.full_clean() 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:12,代碼來源:test_validation.py

示例8: create_index

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Document [as 別名]
def create_index(es, name, doc_class, shards, replicas, synonyms=None,
                 excluding_terms=None):
    """Crea un índice Elasticsearch utilizando un nombre y una clase de
    documento.

    Args:
        es (elasticsearch.Elasticsearch): Cliente Elasticsearch.
        name (str): Nombre del índice a crear.
        doc_class (type): Clase del documento (debe heredar de Document).
        shards (int): Cantidad de "shards" a utilizar para el índice.
        replicas (int): Cantidad de réplicas por "shard".
        synonyms (list): Lista de sinónimos a utilizar en caso de necesitar el
            analizador 'name_analyzer_synonyms'.
        excluding_terms (list): Lista de términos excluyentes a utilizar en
            caso de necesitar el analizador 'name_analyzer_excluding_terms'.

    """
    index = Index(name)

    # Crear el analizador 'name_analyzer_synonyms' solo si se lo pidió
    # explícitamente. Si el documento tipo 'doc_class' utiliza el analizador
    # en algún punto de su mapeo, la lista 'synonyms' debería estar presente.
    if synonyms is not None:
        index.analyzer(gen_name_analyzer_synonyms(synonyms))

    # Mismo razonamiento que con 'name_analyzer_synonyms'.
    if excluding_terms is not None:
        index.analyzer(gen_name_analyzer_excluding_terms(excluding_terms))

    index.document(doc_class)
    index.settings(number_of_shards=shards, number_of_replicas=replicas)
    index.create(using=es) 
開發者ID:datosgobar,項目名稱:georef-ar-api,代碼行數:34,代碼來源:es_config.py


注:本文中的elasticsearch_dsl.Document方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。