Connecting to AWS Elasticsearch instance using Python

前端 未结 2 1055
面向向阳花
面向向阳花 2021-02-09 22:51

I have an Elasticsearch instance, hosted on AWS. I can connect from my terminal with Curl. I am now trying to use the python elasticsearch wrapper. I have:

from          


        
相关标签:
2条回答
  • 2021-02-09 23:37
    host = 'ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com' #without 'https'
    YOUR_ACCESS_KEY = ''
    YOUR_SECRET_KEY = ''
    REGION = 'us-west-2' #change to your region
    awsauth = AWS4Auth(YOUR_ACCESS_KEY, YOUR_SECRET_KEY, REGION, 'es')
    
    es = Elasticsearch(
        hosts=[{'host': host, 'port': 443}],
        http_auth=awsauth,
        use_ssl=True,
        verify_certs=True,
        connection_class=RequestsHttpConnection
    )
    print(es.info())
    
    0 讨论(0)
  • 2021-02-09 23:46

    This is the correct way to connect to elasticsearch server using python:

    es = Elasticsearch(['IP:PORT',])
    

    Elasticsearch's constructor doesn't have the host nor the port parameters. The first parameter should be a list, where each item in the list can be either a string representing the host:

    'schema://ip:port'
    

    Or a dictionary with extended parameters regarding that host

    {'host': 'ip/hostname', 'port': 443, 'url_prefix': 'es', 'use_ssl': True}
    

    In your case you probably would like to use:

     client = Elasticsearch(['https://ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com:9200'])
    

    The port is redundant since you are using the deafult one, so you can use remove it
    client = Elasticsearch(['https://ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com'])

    0 讨论(0)
提交回复
热议问题