当前位置: 首页>>代码示例>>Python>>正文


Python elasticsearch.RequestsHttpConnection方法代码示例

本文整理汇总了Python中elasticsearch.RequestsHttpConnection方法的典型用法代码示例。如果您正苦于以下问题:Python elasticsearch.RequestsHttpConnection方法的具体用法?Python elasticsearch.RequestsHttpConnection怎么用?Python elasticsearch.RequestsHttpConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch的用法示例。


在下文中一共展示了elasticsearch.RequestsHttpConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def __init__(self, conf):
        """
        :arg conf: es_conn_config dictionary. Ref. :func:`~util.build_es_conn_config`
        """
        super(ElasticSearchClient, self).__init__(host=conf['es_host'],
                                                  port=conf['es_port'],
                                                  url_prefix=conf['es_url_prefix'],
                                                  use_ssl=conf['use_ssl'],
                                                  verify_certs=conf['verify_certs'],
                                                  ca_certs=conf['ca_certs'],
                                                  connection_class=RequestsHttpConnection,
                                                  http_auth=conf['http_auth'],
                                                  timeout=conf['es_conn_timeout'],
                                                  send_get_body_as=conf['send_get_body_as'],
                                                  client_cert=conf['client_cert'],
                                                  client_key=conf['client_key'])
        self._conf = copy.copy(conf)
        self._es_version = None 
开发者ID:Yelp,项目名称:elastalert,代码行数:20,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def __init__(self, clair, hosts, index, doc_type, suffix=None, timedelta=None):
        """
        Constructor

        :param clair: ClairRequest object
        :param hosts: elasticsearch hosts ex:[{'host': '172.18.8.10', 'port': 9200}]
        :param index: elasticsearch index
        :param doc_type: elasticsearch doc_type
        :param suffix: index suffix (ex: one index a day)
        :param timedelta: timedelta from today for suffix
        """
        super().__init__(clair, "Legacy")
        self._es = Elasticsearch(hosts, connection_class=RequestsHttpConnection)
        self.index = index
        self.doc_type = doc_type
        if suffix is not None:
            timedelta = timedelta or {}
            self.index += (datetime.datetime.today() + datetime.timedelta(**timedelta)).strftime(suffix) 
开发者ID:yebinama,项目名称:paclair,代码行数:20,代码来源:es_plugin.py

示例3: connect_es

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def connect_es(endpoint):
    # Handle aws auth for es
    session = boto3.Session()
    credentials = session.get_credentials()
    awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, session.region_name, 'es',
                       session_token=credentials.token)
    print('Connecting to the ES Endpoint: {endpoint}'.format(endpoint=endpoint))
    try:
        es_client = Elasticsearch(
            hosts=[{'host': endpoint, 'port': 443}],
            use_ssl=True,
            verify_certs=True,
            http_auth=awsauth,
            connection_class=RequestsHttpConnection)
    except Exception as e:
        print("Unable to connect to {endpoint}:".format(endpoint=endpoint), e)
    else:
        print('Connected to elasticsearch')
        return es_client 
开发者ID:awslabs,项目名称:aws-media-insights-engine,代码行数:21,代码来源:lambda_handler.py

示例4: return_es

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def return_es():
    return Elasticsearch(
        hosts = [{'host': 'elasticsearch', 'port': 9200}],
        connection_class = RequestsHttpConnection,
    ) 
开发者ID:huseinzol05,项目名称:Gather-Deployment,代码行数:7,代码来源:processing.py

示例5: __autorefresh_studies

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def __autorefresh_studies(self, cfg):
        """Execute autorefresh for areas of code study if configured"""

        if 'studies' not in self.conf[self.backend_section] or \
                'enrich_areas_of_code:git' not in self.conf[self.backend_section]['studies']:
            logger.debug("Not doing autorefresh for studies, Areas of Code study is not active.")
            return

        aoc_index = self.conf['enrich_areas_of_code:git'].get('out_index', GitEnrich.GIT_AOC_ENRICHED)

        # if `out_index` exists but has no value, use default
        if not aoc_index:
            aoc_index = GitEnrich.GIT_AOC_ENRICHED

        logger.debug("Autorefresh for Areas of Code study index: %s", aoc_index)

        es = Elasticsearch([self.conf['es_enrichment']['url']], timeout=100, retry_on_timeout=True,
                           verify_certs=self._get_enrich_backend().elastic.requests.verify,
                           connection_class=RequestsHttpConnection)

        if not es.indices.exists(index=aoc_index):
            logger.debug("Not doing autorefresh, index doesn't exist for Areas of Code study")
            return

        logger.debug("Doing autorefresh for Areas of Code study")

        # Create a GitEnrich backend tweaked to work with AOC index
        aoc_backend = GitEnrich(self.db_sh, None, cfg['projects']['projects_file'],
                                self.db_user, self.db_password, self.db_host)
        aoc_backend.mapping = None
        aoc_backend.roles = ['author']
        elastic_enrich = get_elastic(self.conf['es_enrichment']['url'],
                                     aoc_index, clean=False, backend=aoc_backend)
        aoc_backend.set_elastic(elastic_enrich)

        self.__autorefresh(aoc_backend, studies=True) 
开发者ID:chaoss,项目名称:grimoirelab-sirmordred,代码行数:38,代码来源:task_enrich.py

示例6: es

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def es():
    class Elasticsearch(object):
        def __init__(self, url):
            verify = default.from_env("PYTHONHTTPSVERIFY") == "1"
            self.es = elasticsearch.Elasticsearch(url,
                                                  verify_certs=verify,
                                                  connection_class=elasticsearch.RequestsHttpConnection)
            self.index = "apm-*"

        def clean(self):
            self.es.indices.delete(self.index)
            self.es.indices.refresh()

        def term_q(self, filters):
            clauses = []
            for field, value in filters:
                if isinstance(value, list):
                    clause = {"terms": {field: value}}
                else:
                    clause = {"term": {field: {"value": value}}}
                clauses.append(clause)
            return {"query": {"bool": {"must": clauses}}}

        @timeout_decorator.timeout(10)
        def count(self, q):
            ct = 0
            while ct == 0:
                time.sleep(3)
                s = self.es.count(index=self.index, body=q)
                ct = s['count']
            return ct

    return Elasticsearch(getElasticsearchURL()) 
开发者ID:elastic,项目名称:apm-integration-testing,代码行数:35,代码来源:es.py

示例7: _elasticsearch_builder

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def _elasticsearch_builder(self):
        """Builds an Elasticsearch obj with the necessary credentials, proxy settings and secure connection."""
        return Elasticsearch(hosts=[self._server], connection_class=RequestsHttpConnection, http_auth=self._http_auth,
                             verify_certs=self._insecure, proxies=self._proxy, api_key=self._api_key) 
开发者ID:demisto,项目名称:content,代码行数:6,代码来源:FeedElasticsearch.py

示例8: _elasticsearch_connect

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def _elasticsearch_connect():
    """
    Connect to configured Elasticsearch domain.

    :return: An Elasticsearch connection object.
    """
    auth = AWSRequestsAuth(
        aws_access_key=settings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
        aws_host=settings.ELASTICSEARCH_URL,
        aws_region=settings.ELASTICSEARCH_AWS_REGION,
        aws_service='es'
    )
    auth.encode = lambda x: bytes(x.encode('utf-8'))
    _es = Elasticsearch(
        host=settings.ELASTICSEARCH_URL,
        port=settings.ELASTICSEARCH_PORT,
        connection_class=RequestsHttpConnection,
        timeout=10,
        max_retries=1,
        retry_on_timeout=True,
        http_auth=auth,
        wait_for_status='yellow'
    )
    _es.info()
    return _es 
开发者ID:creativecommons,项目名称:cccatalog-api,代码行数:28,代码来源:search_controller.py

示例9: test03_upstream_indexed

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def test03_upstream_indexed(self):
        """
        Check that the data has been successfully indexed in Elasticsearch.
        """
        es = Elasticsearch(
            host='localhost',
            port=60001,
            connection_class=RequestsHttpConnection,
            timeout=10,
            max_retries=10,
            retry_on_timeout=True,
            http_auth=None,
            wait_for_status='yellow'
        )
        es_query = {
            "query": {
                "match_all": {}
            }
        }
        es.indices.refresh(index='image')
        search_response = es.search(
            index="image",
            body=es_query
        )
        msg = 'There should be 1000 documents in Elasticsearch after ingestion.'
        self.assertEquals(search_response['hits']['total'], 1000, msg) 
开发者ID:creativecommons,项目名称:cccatalog-api,代码行数:28,代码来源:integration_tests.py

示例10: test05_removed_from_source_not_indexed

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def test05_removed_from_source_not_indexed(self):
        id_to_check = 10494466  #Index for which we changed manually False to True
        es = Elasticsearch(
            host='localhost',
            port=60001,
            connection_class=RequestsHttpConnection,
            timeout=10,
            max_retries=10,
            retry_on_timeout=True,
            http_auth=None,
            wait_for_status='yellow'
        )
        es_query = {
            "query": {
                "match": {
                    "_id": id_to_check
                }
            }
        }
        es.indices.refresh(index='image')
        search_response = es.search(
            index="image",
            body=es_query
        )

        num_hits = search_response['hits']['total']
        msg = "id {} should not show up in search results.".format(id_to_check)
        self.assertEqual(0, num_hits, msg) 
开发者ID:creativecommons,项目名称:cccatalog-api,代码行数:30,代码来源:integration_tests.py

示例11: init_es

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def init_es(timeout=TIMEOUT):
    log.info("connecting to %s %s", settings.ELASTICSEARCH_URL, settings.ELASTICSEARCH_PORT)
    auth = AWSRequestsAuth(aws_access_key=settings.AWS_ACCESS_KEY_ID,
                           aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
                           aws_host=settings.ELASTICSEARCH_URL,
                           aws_region='us-west-1',
                           aws_service='es')
    auth.encode = lambda x: bytes(x.encode('utf-8'))
    es = Elasticsearch(host=settings.ELASTICSEARCH_URL,
                       port=settings.ELASTICSEARCH_PORT,
                       connection_class=RequestsHttpConnection,
                       timeout=timeout,
                       max_retries=10, retry_on_timeout=True,
                       http_auth=auth)
    return es 
开发者ID:cc-archive,项目名称:open-ledger,代码行数:17,代码来源:search.py

示例12: new_es_client

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def new_es_client(hosts):
    return Elasticsearch(hosts=hosts,
                         maxsize=50,
                         timeout=1800,
                         # sniff_on_connection_fail=True,
                         # sniff_on_start=True,
                         # sniffer_timeout=60,
                         retry_on_timeout=True,
                         max_retries=10,
                         connection_class=RequestsHttpConnection,
                         verify_certs=True) 
开发者ID:opentargets,项目名称:data_pipeline,代码行数:13,代码来源:connection.py

示例13: make_elasticsearch_client

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def make_elasticsearch_client(elasticsearch_endpoint):
    awsauth = AWSRequestsAuth(
        aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
        aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
        aws_token=os.environ['AWS_SESSION_TOKEN'],
        aws_host=elasticsearch_endpoint,
        aws_region=os.environ['AWS_REGION'],
        aws_service='es'
    )
    return Elasticsearch(
        hosts=['{0}:443'.format(elasticsearch_endpoint)],
        use_ssl=True,
        connection_class=RequestsHttpConnection,
        http_auth=awsauth
    ) 
开发者ID:aws-quickstart,项目名称:quickstart-datalake-47lining,代码行数:17,代码来源:lambdas.py

示例14: __init__

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def __init__(self):
        """Open connection on Elasticsearch DataBase"""
        super(Elasticsearch, self).__init__()
        self.search = True
        self.conn = ES([{"host": self.conf.get('host'),
                         "port": int(self.conf.get('port'))}],
                       connection_class=RequestsHttpConnection)
        self.base_url = self.conn.transport.get_connection().base_url 
开发者ID:mining,项目名称:mining,代码行数:10,代码来源:melasticsearch.py

示例15: lambda_handler

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import RequestsHttpConnection [as 别名]
def lambda_handler(event, context):
    '''
    lambda handler to create index templates 
    '''    
    status = True
    host = os.environ['ElasticsearchEndpoint']

    logger.info('REQUEST RECEIVED:\n {}'.format(event))
    logger.info('REQUEST RECEIVED:\n {}'.format(context))
    
    try:   
        if event['RequestType'] == 'Create':
            logger.info('CREATE!')

            session = boto3.Session()
            credentials = session.get_credentials()
            awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, session.region_name, 'es', session_token=credentials.token)

            es = Elasticsearch([{'host': host, 'port': 443}], http_auth = awsauth, use_ssl = True, verify_certs=True, connection_class = RequestsHttpConnection)
            result = es.indices.put_template(name='jobtemplate', body=job_index_template)
            status1 = result.get('acknowledged', False)
            result = es.indices.put_template(name='metrictemplate', body=metric_index_template)
            status2 = result.get('acknowledged', False)
            if (status1 == False or status2 == False):
                send(event, context, "FAILED", { "Message": "Resource creation failed!" }, None)
            else:
                send(event, context, "SUCCESS", { "Message": "Resource creation successful!" }, None)
        elif event['RequestType'] == 'Update':
            logger.info('UPDATE!')
            send(event, context, "SUCCESS", { "Message": "Resource update successful!" }, None)
        elif event['RequestType'] == 'Delete':
            logger.info('DELETE!')
            send(event, context, "SUCCESS", { "Message": "Resource deletion successful!" }, None)
        else:
            logger.info('FAILED!')
            send(event, context, "FAILED", { "Message": "Unexpected event received from CloudFormation" }, None)
    
    except Exception as e:
        message = "Unexected error creating mapping: {}".format(e)
        send(event, context, "FAILED", { "Message": message }, None)
            
    return status 
开发者ID:aws-samples,项目名称:aws-media-services-vod-automation,代码行数:44,代码来源:index-custom-resource.py


注:本文中的elasticsearch.RequestsHttpConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。