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


Python elasticsearch.TransportError方法代碼示例

本文整理匯總了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) 
開發者ID:o19s,項目名稱:elyzer,代碼行數:21,代碼來源:__main__.py

示例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 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:25,代碼來源:elasticv2.py

示例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 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:20,代碼來源:elasticv2.py

示例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 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:21,代碼來源:elasticv2.py

示例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 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:20,代碼來源:elastic.py

示例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) 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:20,代碼來源:elastic.py

示例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 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:22,代碼來源:elastic.py

示例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 
開發者ID:elastic,項目名稱:rally,代碼行數:24,代碼來源:runner.py

示例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) 
開發者ID:elastic,項目名稱:rally,代碼行數:27,代碼來源:telemetry.py

示例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) 
開發者ID:elastic,項目名稱:rally,代碼行數:19,代碼來源:runner_test.py

示例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
                                                             }) 
開發者ID:elastic,項目名稱:rally,代碼行數:19,代碼來源:runner_test.py

示例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"]
                                                             }) 
開發者ID:elastic,項目名稱:rally,代碼行數:21,代碼來源:runner_test.py

示例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
                                                             }) 
開發者ID:elastic,項目名稱:rally,代碼行數:20,代碼來源:runner_test.py

示例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"]
                                                             }) 
開發者ID:elastic,項目名稱:rally,代碼行數:21,代碼來源:runner_test.py

示例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 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:23,代碼來源:test_search.py


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