User authentication in Elasticsearch query using python

30,126

Solution 1

You need to pass the username and password to the Elasticsearch object as shown below:

es = Elasticsearch(['http://localhost:8080'], http_auth=('user', 'pass'))

Solution 2

You can pass username, password in url:

ex:

username: elastic

password: changeme

es = Elasticsearch(hosts="http://elastic:changeme@localhost:9200/")

using CURL

curl -X GET "elastic:changeme@localhost:9200/"

Solution 3

es = Elasticsearch([{'host': 'localhost', 'port': '8080'}], http_auth=('user', 'pass'))

Solution 4

you can connect the elasticsearch with below Host url config

es = Elasticsearch(hosts="http://user:pass@localhost:9200/")
Share:
30,126
Mayank Jha
Author by

Mayank Jha

Updated on January 19, 2021

Comments

  • Mayank Jha
    Mayank Jha over 3 years

    I'm using elastisearch using Python. My code looks somewhat like this:-

                  
    from elasticsearch import Elasticsearch
    
    if __name__ == '__main__': 
        index="IndexPosition"
        es=Elasticsearch(['https://localhost:8080'])
        res = es.search(index='{0}'.format(index), doc_type="log",size=1000, from_=0, body={ "query": {
        "match": {
          
            ...Match condition
          }
        }
      }})
    

    Now, due to changes in architecture user authentication has been added in the elasticsearch.Let's assume username-user and password-pass.How do I pass the username and password in the query..?