本文整理汇总了Python中elasticsearch.RequestError方法的典型用法代码示例。如果您正苦于以下问题:Python elasticsearch.RequestError方法的具体用法?Python elasticsearch.RequestError怎么用?Python elasticsearch.RequestError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch
的用法示例。
在下文中一共展示了elasticsearch.RequestError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_es_client
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestError [as 别名]
def get_es_client(self):
self._es = Elasticsearch(hosts=self.es_hosts)
self._es_version = [int(i) for i in self._es.info()["version"]["number"].split(".")]
if self._es_version < [7]:
raise ValueError("Inventory exporter {} not compatible with ES < 7.0")
# lifecycle
_esilm = IlmClient(self._es)
_esilm.put_lifecycle(ES_LIFECYCLE_POLICY_NAME, ES_LIFECYCLE_POLICY)
# template
self._es.indices.put_template(ES_TEMPLATE_NAME, ES_TEMPLATE)
# create index
for i in range(10):
existing_indices = self._es.indices.get(ES_INDEX_PATTERN).keys()
if not len(existing_indices):
current_index_name = ES_INDEX_PATTERN.replace("*", "000001")
try:
self._es.indices.create(current_index_name, {"aliases": {ES_ALIAS: {"is_write_index": True}}})
except RequestError:
# probably race
pass
else:
break
return ES_ALIAS
示例2: get_es_client
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestError [as 别名]
def get_es_client(self):
self._es = Elasticsearch(hosts=self.es_hosts)
self._es_version = [int(i) for i in self._es.info()["version"]["number"].split(".")]
# template
template_body = ES_TEMPLATE
if self._es_version < [7]:
template_body["mappings"] = {"_doc": template_body.pop("mappings")}
self._es.indices.put_template(ES_TEMPLATE_NAME, template_body)
# create index
for i in range(10):
existing_indices = self._es.indices.get(ES_INDEX_PATTERN).keys()
if not len(existing_indices):
next_id = 0
else:
next_id = max(int(index.rsplit("-", 1)[-1]) for index in existing_indices) + 1
index_name = ES_INDEX_PATTERN.replace("*", "{:08d}".format(next_id))
try:
self._es.indices.create(index_name)
except RequestError:
# probably race
pass
else:
# move alias
update_aliases_body = {
"actions": [
{"add": {"index": index_name, "alias": ES_ALIAS}}
]
}
try:
old_indices = self._es.indices.get_alias(ES_ALIAS)
except NotFoundError:
old_indices = []
for old_index in old_indices:
if old_index != index_name:
update_aliases_body["actions"].append(
{"remove": {"index": old_index, "alias": ES_ALIAS}}
)
self._es.indices.update_aliases(update_aliases_body)
return index_name
示例3: create_index
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestError [as 别名]
def create_index(self):
"""Tell the Elasticsearch client to create the index as configured."""
self.logger.debug("creating index %s", self.index_name)
body = {
"settings": self.settings,
"mappings": self.mappings
}
try:
self.client.indices.create(index=self.index_name, body=body)
except RequestError as e:
if u'resource_already_exists_exception' == e.error:
self.logger.debug("swallowing index exists exception")
else:
# if it wasn't this error, raise it again
raise e
示例4: put_object
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestError [as 别名]
def put_object(self, obj):
# TODO consider putting into a ES class
self.pr_dbg('put_obj: %s' % self.json_dumps(obj))
"""
Wrapper for es.index, determines metadata needed to index from obj.
If you have a raw object json string you can hard code these:
index is .kibana (as of kibana4);
id can be A-Za-z0-9\- and must be unique;
doc_type is either visualization, dashboard, search
or for settings docs: config, or index-pattern.
"""
if obj['_index'] is None or obj['_index'] == "":
raise Exception("Invalid Object, no index")
if obj['_id'] is None or obj['_id'] == "":
raise Exception("Invalid Object, no _id")
if obj['_type'] is None or obj['_type'] == "":
raise Exception("Invalid Object, no _type")
if obj['_source'] is None or obj['_source'] == "":
raise Exception("Invalid Object, no _source")
self.connect_es()
self.es.indices.create(index=obj['_index'], ignore=400, timeout="2m")
try:
resp = self.es.index(index=obj['_index'],
id=obj['_id'],
doc_type=obj['_type'],
body=obj['_source'], timeout="2m")
except RequestError as e:
self.pr_err('RequestError: %s, info: %s' % (e.error, e.info))
raise
return resp
示例5: _run_query
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestError [as 别名]
def _run_query(self, es_query, result_type):
try:
results = config.es.search(
index='data_explorer',
doc_type='flywheel',
body=es_query
)
except RequestError:
self.abort(400, 'Unable to parse filters - invalid format.')
return self._process_results(results, result_type)