0

I have connected to Elastic Search(ES) with below code, but its not returning True. http://localhost:9200/ is giving proper output

name    "0jDPVkL"
cluster_name    "elasticsearch"
cluster_uuid    "9PfIve-HSP-v7kU__DbGmQ"
version 
number  "6.4.1"
build_flavor    "default"
build_type  "zip"
build_hash  "e36acdb"
build_date  "2018-09-13T22:18:07.696808Z"
build_snapshot  false
lucene_version  "7.4.0"
minimum_wire_compatibility_version  "5.6.0"
minimum_index_compatibility_version "5.0.0"
tagline "You Know, for Search"

The Python Code

import logging
def connect_elasticsearch():
    _es = None
    _es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
    if _es.ping():
        print('Yay Connect')
    else:
        print('Awww it could not connect!')
    return _es

if __name__ == '__main__':
    logging.basicConfig(level=logging.ERROR)

I am trying to execute from the URL http://blog.adnansiddiqi.me/getting-started-with-elasticsearch-in-python/

2
  • Try pass kwarg retry_on_timeout=True to Elasticsearch init Commented Oct 2, 2018 at 7:43
  • tried retry_on_timeout=True but still issue persists Commented Oct 3, 2018 at 8:53

1 Answer 1

1

I have tested your code from the blog. Its working fine. I uploaded in the github also

https://github.com/mak705/Python_ELK/blob/master/recipie.ipynb

Courtesy : Adnan who wrote the blog http://blog.adnansiddiqi.me/getting-started-with-elasticsearch-in-python/

NB: In latest version of ES(6,x) we don't need to mention mapping tags that is starting from the mapping { . Its automatically detects and give the schema. In earlier version(5.x) we have to mention the schema

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.