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


Python elasticsearch.RequestError方法代碼示例

本文整理匯總了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 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:25,代碼來源:es_aggregations.py

示例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 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:41,代碼來源:es_machine_snapshots.py

示例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 
開發者ID:opentargets,項目名稱:data_pipeline,代碼行數:17,代碼來源:esutil.py

示例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 
開發者ID:rfarley3,項目名稱:Kibana,代碼行數:32,代碼來源:manager.py

示例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) 
開發者ID:scitran,項目名稱:core,代碼行數:13,代碼來源:dataexplorerhandler.py


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