本文整理汇总了Python中elasticsearch.TransportError方法的典型用法代码示例。如果您正苦于以下问题:Python elasticsearch.TransportError方法的具体用法?Python elasticsearch.TransportError怎么用?Python elasticsearch.TransportError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch
的用法示例。
在下文中一共展示了elasticsearch.TransportError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def main():
try:
args = parse_args()
es = Elasticsearch(args['es'])
stepWise(es=es,
text=args['text'],
indexName=args['index'],
analyzer=getAnalyzer(indexName=args['index'],
analyzerName=args['analyzer'],
es=es))
except KeyboardInterrupt:
print('Interrupted')
except AnalyzerNotFound as e:
print(e.error)
except TransportError as e:
print("Unexpected Elasticsearch Transport Exception:")
print(e.error)
print(e.info)
示例2: get
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def get(self, project_id, doc_id, user_id=None):
try:
res = self.es.get(index=self.index,
doc_type=self.doc_type,
id=doc_id)
doc = res['_source']
except elasticsearch.TransportError:
raise freezer_api_exc.DocumentNotFound(
message='No document found with ID:{0}'.format(doc_id))
except Exception as e:
raise freezer_api_exc.StorageEngineError(
message='Get operation failed: {}'.format(e))
if doc['project_id'] != project_id:
raise freezer_api_exc.AccessForbidden("You are not allowed to"
" access")
if user_id:
if doc['user_id'] != user_id:
raise freezer_api_exc.AccessForbidden(
"Document access forbidden"
)
if '_version' in res:
doc['_version'] = res['_version']
return doc
示例3: insert
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def insert(self, doc, doc_id=None):
try:
# remove _version from the document
doc.pop('_version', None)
res = self.es.index(index=self.index, doc_type=self.doc_type,
body=doc, id=doc_id)
created = res['created']
version = res['_version']
self.es.indices.refresh(index=self.index)
except elasticsearch.TransportError as e:
if e.status_code == 409:
raise freezer_api_exc.DocumentExists(message=e.error)
raise freezer_api_exc.StorageEngineError(
message='index operation failed {0}'.format(e))
except Exception as e:
raise freezer_api_exc.StorageEngineError(
message='index operation failed {0}'.format(e))
return created, version
示例4: update
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def update(self, job_id, job_update_doc):
# remove _version from the document
job_update_doc.pop('_version', 0)
update_doc = {"doc": job_update_doc}
try:
res = self.es.update(index=self.index, doc_type=self.doc_type,
id=job_id, body=update_doc)
version = res['_version']
self.es.indices.refresh(index=self.index)
except elasticsearch.TransportError as e:
if e.status_code == 409:
raise freezer_api_exc.DocumentExists(message=e.error)
raise freezer_api_exc.DocumentNotFound(
message='Unable to find job to update with id'
' {0} {1}'.format(job_id, e))
except Exception:
raise freezer_api_exc.StorageEngineError(
message='Unable to update job with id {0}'.format(job_id))
return version
示例5: get
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def get(self, user_id, doc_id):
try:
res = self.es.get(index=self.index,
doc_type=self.doc_type,
id=doc_id)
doc = res['_source']
except elasticsearch.TransportError:
raise freezer_api_exc.DocumentNotFound(
message=_i18n._('No document found with ID %s') % doc_id)
except Exception as e:
raise freezer_api_exc.StorageEngineError(
message=_i18n._('Get operation failed: %s') % e)
if doc['user_id'] != user_id:
raise freezer_api_exc.AccessForbidden(
_i18n._("Document access forbidden"))
if '_version' in res:
doc['_version'] = res['_version']
return doc
示例6: insert
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def insert(self, doc, doc_id=None):
try:
# remove _version from the document
doc.pop('_version', None)
res = self.es.index(index=self.index, doc_type=self.doc_type,
body=doc, id=doc_id)
created = res['created']
version = res['_version']
self.es.indices.refresh(index=self.index)
except elasticsearch.TransportError as e:
if e.status_code == 409:
raise freezer_api_exc.DocumentExists(message=e.error)
raise freezer_api_exc.StorageEngineError(
message=_i18n._('index operation failed %s') % e)
except Exception as e:
raise freezer_api_exc.StorageEngineError(
message=_i18n._('index operation failed %s') % e)
return (created, version)
示例7: update
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def update(self, job_id, job_update_doc):
# remove _version from the document
job_update_doc.pop('_version', 0)
update_doc = {"doc": job_update_doc}
try:
res = self.es.update(index=self.index, doc_type=self.doc_type,
id=job_id, body=update_doc)
version = res['_version']
self.es.indices.refresh(index=self.index)
except elasticsearch.TransportError as e:
if e.status_code == 409:
raise freezer_api_exc.DocumentExists(message=e.error)
raise freezer_api_exc.DocumentNotFound(
message=_i18n._('Unable to find job to update '
'with id %(id)s. %(e)s') % {'id': job_id,
'e': e})
except Exception:
raise freezer_api_exc.StorageEngineError(
message=_i18n._('Unable to update job with id %s') % job_id)
return version
示例8: __call__
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def __call__(self, es, params):
import elasticsearch
max_num_segments = params.get("max-num-segments")
# preliminary support for overriding the global request timeout (see #567). As force-merge falls back to
# the raw transport API (where the keyword argument is called `timeout`) in some cases we will always need
# a special handling for the force-merge API.
request_timeout = params.get("request-timeout")
try:
if max_num_segments:
await es.indices.forcemerge(index=params.get("index"), max_num_segments=max_num_segments, request_timeout=request_timeout)
else:
await es.indices.forcemerge(index=params.get("index"), request_timeout=request_timeout)
except elasticsearch.TransportError as e:
# this is caused by older versions of Elasticsearch (< 2.1), fall back to optimize
if e.status_code == 400:
if max_num_segments:
await es.transport.perform_request("POST", f"/_optimize?max_num_segments={max_num_segments}",
timeout=request_timeout)
else:
await es.transport.perform_request("POST", "/_optimize", timeout=request_timeout)
else:
raise e
示例9: record
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def record(self):
"""
Collect recovery stats for indexes (optionally) specified in telemetry parameters and push to metrics store.
"""
import elasticsearch
try:
stats = self.client.indices.recovery(index=self.indices, active_only=True, detailed=False)
except elasticsearch.TransportError:
msg = "A transport error occurred while collecting recovery stats on cluster [{}]".format(self.cluster_name)
self.logger.exception(msg)
raise exceptions.RallyError(msg)
for idx, idx_stats in stats.items():
for shard in idx_stats["shards"]:
doc = {
"name": "recovery-stats",
"shard": shard
}
shard_metadata = {
"cluster": self.cluster_name,
"index": idx,
"shard": shard["id"]
}
self.metrics_store.put_doc(doc, level=MetaInfoScope.cluster, meta_data=shard_metadata)
示例10: test_create_ml_datafeed_fallback
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_create_ml_datafeed_fallback(self, es):
es.xpack.ml.put_datafeed.side_effect = as_future(exception=elasticsearch.TransportError(400, "Bad Request"))
es.transport.perform_request.return_value = as_future()
datafeed_id = "some-data-feed"
body = {
"job_id": "total-requests",
"indices": ["server-metrics"]
}
params = {
"datafeed-id": datafeed_id,
"body": body
}
r = runner.CreateMlDatafeed()
await r(es, params)
es.transport.perform_request.assert_called_once_with("PUT", f"/_xpack/ml/datafeeds/{datafeed_id}", body=body)
示例11: test_delete_ml_datafeed_fallback
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_delete_ml_datafeed_fallback(self, es):
es.xpack.ml.delete_datafeed.side_effect = as_future(exception=elasticsearch.TransportError(400, "Bad Request"))
es.transport.perform_request.return_value = as_future()
datafeed_id = "some-data-feed"
params = {
"datafeed-id": datafeed_id,
}
r = runner.DeleteMlDatafeed()
await r(es, params)
es.transport.perform_request.assert_called_once_with("DELETE",
f"/_xpack/ml/datafeeds/{datafeed_id}",
params={
"force": "false",
"ignore": 404
})
示例12: test_stop_ml_datafeed_fallback
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_stop_ml_datafeed_fallback(self, es):
es.xpack.ml.stop_datafeed.side_effect = as_future(exception=elasticsearch.TransportError(400, "Bad Request"))
es.transport.perform_request.return_value = as_future()
params = {
"datafeed-id": "some-data-feed",
"force": random.choice([False, True]),
"timeout": "5s"
}
r = runner.StopMlDatafeed()
await r(es, params)
es.transport.perform_request.assert_called_once_with("POST",
f"/_xpack/ml/datafeeds/{params['datafeed-id']}/_stop",
params={
"force": str(params["force"]).lower(),
"timeout": params["timeout"]
})
示例13: test_delete_ml_job_fallback
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_delete_ml_job_fallback(self, es):
es.xpack.ml.delete_job.side_effect = as_future(exception=elasticsearch.TransportError(400, "Bad Request"))
es.transport.perform_request.return_value = as_future()
job_id = "an-ml-job"
params = {
"job-id": job_id
}
r = runner.DeleteMlJob()
await r(es, params)
es.transport.perform_request.assert_called_once_with("DELETE",
f"/_xpack/ml/anomaly_detectors/{params['job-id']}",
params={
"force": "false",
"ignore": 404
})
示例14: test_close_ml_job_fallback
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_close_ml_job_fallback(self, es):
es.xpack.ml.close_job.side_effect = as_future(exception=elasticsearch.TransportError(400, "Bad Request"))
es.transport.perform_request.return_value = as_future()
params = {
"job-id": "an-ml-job",
"force": random.choice([False, True]),
"timeout": "5s"
}
r = runner.CloseMlJob()
await r(es, params)
es.transport.perform_request.assert_called_once_with("POST",
f"/_xpack/ml/anomaly_detectors/{params['job-id']}/_close",
params={
"force": str(params["force"]).lower(),
"timeout": params["timeout"]
})
示例15: test_multi_missing
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import TransportError [as 别名]
def test_multi_missing(data_client):
s1 = Repository.search()
s2 = Search(index='flat-git')
s3 = Search(index='does_not_exist')
ms = MultiSearch()
ms = ms.add(s1).add(s2).add(s3)
with raises(TransportError):
ms.execute()
r1, r2, r3 = ms.execute(raise_on_error=False)
assert 1 == len(r1)
assert isinstance(r1[0], Repository)
assert r1._search is s1
assert 52 == r2.hits.total.value
assert r2._search is s2
assert r3 is None