本文整理汇总了Python中elasticsearch_dsl.Index.aliases方法的典型用法代码示例。如果您正苦于以下问题:Python Index.aliases方法的具体用法?Python Index.aliases怎么用?Python Index.aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch_dsl.Index
的用法示例。
在下文中一共展示了Index.aliases方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_index
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [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()
示例2: test_aliases_returned_from_to_dict
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [as 别名]
def test_aliases_returned_from_to_dict():
random_alias = ''.join((choice(string.ascii_letters) for _ in range(100)))
alias_dict = {random_alias: {}}
index = Index('i', using='alias')
index.aliases(**alias_dict)
assert index._aliases == index.to_dict()['aliases'] == alias_dict
示例3: test_aliases_add_to_object
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [as 别名]
def test_aliases_add_to_object():
random_alias = ''.join((choice(string.ascii_letters) for _ in range(100)))
alias_dict = {random_alias: {}}
index = Index('i', using='alias')
index.aliases(**alias_dict)
assert index._aliases == alias_dict
示例4: _create_index
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [as 别名]
def _create_index(self):
dt = datetime.utcnow()
dt = dt.strftime('%Y.%m')
es = connections.get_connection()
if not es.indices.exists('indicators-{}'.format(dt)):
index = Index('indicators-{}'.format(dt))
index.aliases(live={})
index.doc_type(Indicator)
index.create()
m = Mapping('indicator')
m.field('indicator_ipv4', 'ip')
m.field('indicator_ipv4_mask', 'integer')
m.save('indicators-{}'.format(dt))
return 'indicators-{}'.format(dt)
示例5: _create_index
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [as 别名]
def _create_index(self):
# https://github.com/csirtgadgets/massive-octo-spice/blob/develop/elasticsearch/observables.json
# http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch.bulk
# every time we check it does a HEAD req
if self.last_index_value and (datetime.utcnow() - self.last_index_check) < timedelta(minutes=2):
return self.last_index_value
idx = self._current_index()
if not self.handle.indices.exists(idx):
index = Index(idx)
index.aliases(live={})
index.doc_type(Indicator)
index.settings(max_result_window=WINDOW_LIMIT)
index.create()
self.handle.indices.flush(idx)
self.last_index_check = datetime.utcnow()
self.last_index_value = idx
return idx
示例6: register
# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import aliases [as 别名]
def register(self, name=None, version=None, settings=None):
"""
Register an index locally.
Note that `createall` is needed to save the index to Elasticsearch.
The index will be named per convention such that:
- The graph's name is used by default
- The "test" suffix is added for unit testing (to avoid clobbering real data)
If version is provided, it will be used to create generate an alias (to the unversioned name).
"""
if version is None:
index_name = IndexRegistry.name_for(self.graph, name=name)
alias_name = None
else:
# create index with full version, alias to shortened version
index_name = IndexRegistry.name_for(self.graph, name=name, version=version)
alias_name = IndexRegistry.name_for(self.graph, name=name)
if index_name in self.indexes:
raise Exception("Index already registered for name: {}".format(index_name))
index = Index(
name=index_name,
using=self.graph.elasticsearch_client,
)
if settings:
index.settings(**settings)
if alias_name is not None:
index.aliases(**{alias_name: {}})
self.indexes[index_name] = index
return index