本文整理汇总了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
示例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()
示例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
示例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)
示例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
示例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()
示例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()
示例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)