{"id":8134,"library":"elasticsearch6","title":"Elasticsearch 6 Python Client","description":"The `elasticsearch6` library is the official low-level Python client for Elasticsearch, specifically designed for compatibility with Elasticsearch 6.x servers. It provides a foundation for interacting with Elasticsearch, focusing on being opinion-free and highly extendable. While the main `elasticsearch` client has progressed to newer major versions (e.g., 9.x), `elasticsearch6` remains available on PyPI to support applications tied to Elasticsearch 6.x. It was last released in March 2021.","status":"maintenance","version":"6.8.2","language":"en","source_language":"en","source_url":"https://github.com/elastic/elasticsearch-py","tags":["Elasticsearch","database client","search","deprecated client"],"install":[{"cmd":"pip install elasticsearch6","lang":"bash","label":"Install for Elasticsearch 6.x"}],"dependencies":[],"imports":[{"note":"Despite the package name 'elasticsearch6', the primary client class is imported from the 'elasticsearch' namespace. This is a common pattern for version-specific clients.","wrong":"from elasticsearch6 import Elasticsearch","symbol":"Elasticsearch","correct":"from elasticsearch import Elasticsearch"}],"quickstart":{"code":"from datetime import datetime\nfrom elasticsearch import Elasticsearch\nimport os\n\n# By default, connects to localhost:9200. \n# Ensure an Elasticsearch 6.x instance is running or specify host/port.\n# For local testing, you might run Elasticsearch via Docker, e.g.:\n# docker run -p 9200:9200 -e \"discovery.type=single-node\" -e \"xpack.security.enabled=false\" docker.elastic.co/elasticsearch/elasticsearch:6.8.23\n\n# Configure connection. Use environment variables for production credentials.\n# Example for basic auth (if security is enabled on ES 6.x):\n# ELASTIC_HOST = os.environ.get('ELASTIC_HOST', 'http://localhost:9200')\n# ELASTIC_USER = os.environ.get('ELASTIC_USER', 'elastic')\n# ELASTIC_PASSWORD = os.environ.get('ELASTIC_PASSWORD', 'changeme')\n# es = Elasticsearch(\n#     [ELASTIC_HOST],\n#     http_auth=(ELASTIC_USER, ELASTIC_PASSWORD),\n#     verify_certs=False,  # Use with caution for self-signed or development certs\n# )\nes = Elasticsearch('http://localhost:9200') # Connects to a local ES instance without security\n\nif not es.ping():\n    raise ValueError(\"Connection to Elasticsearch failed!\")\n\nprint(\"Connected to Elasticsearch!\")\n\nindex_name = 'my_test_index_6'\ndoc_type_name = 'my_document_type' # Required in ES 6.x\n\n# Create an index (ignore 400 if it already exists)\nes.indices.create(index=index_name, ignore=400)\n\n# Index a document\ndoc = {\n    'author': 'kimchy',\n    'text': 'Elasticsearch 6.x is stable.',\n    'timestamp': datetime.now()\n}\nres = es.index(index=index_name, doc_type=doc_type_name, id=1, body=doc)\nprint(f\"Indexed document ID 1: {res['result']}\")\n\n# Get a document\nres = es.get(index=index_name, doc_type=doc_type_name, id=1)\nprint(f\"Retrieved document: {res['_source']}\")\n\n# Search for documents\nres = es.search(index=index_name, doc_type=doc_type_name, body={\n    \"query\": {\"match\": {\"author\": \"kimchy\"}}\n})\n\nprint(f\"Found {res['hits']['total']['value']} hits:\")\nfor hit in res['hits']['hits']:\n    print(f\"  {hit['_source']['author']}: {hit['_source']['text']}\")\n\n# Delete the index\nes.indices.delete(index=index_name, ignore=[400, 404])\nprint(f\"Index '{index_name}' deleted.\")","lang":"python","description":"This quickstart demonstrates how to connect to an Elasticsearch 6.x instance, create an index, index a document, retrieve it, perform a basic search, and delete the index. Note the explicit use of `doc_type` which is mandatory for Elasticsearch 6.x."},"warnings":[{"fix":"Ensure `doc_type` is always provided when using `elasticsearch6` client. When migrating to newer Elasticsearch clients (v7+), refactor code to use typeless endpoints (e.g., `_doc` instead of `_doc_type`) and update API calls as per the target Elasticsearch server version's documentation.","message":"The `_doc_type` parameter is mandatory for indexing and searching in Elasticsearch 6.x. Migrating to Elasticsearch 7.x or later servers (and their corresponding Python clients) will deprecate and eventually remove the `_doc_type` concept, requiring changes to API calls.","severity":"breaking","affected_versions":"All versions of elasticsearch6 client (when interacting with Elasticsearch server versions 7.x+)"},{"fix":"Review Elasticsearch server deprecation logs (using `_cluster/settings?include_defaults=true` or the Deprecation Info API) for warnings about `_version` or other deprecated functionalities. Plan to refactor usage of these fields when considering an upgrade to Elasticsearch 7.x or later.","message":"Elasticsearch 6.x deprecated the use of the `_version` field and similar metadata fields in certain contexts, which were fully removed in Elasticsearch 7.x. Using `elasticsearch6` client against an Elasticsearch 6.x server may still generate deprecation warnings if these features are utilized.","severity":"deprecated","affected_versions":"All versions of elasticsearch6 client (when interacting with Elasticsearch 6.x server, if deprecated features are used)"},{"fix":"For secure clusters, provide `http_auth=(username, password)` or `api_key` in the `Elasticsearch` client constructor. Ensure `ca_certs` is configured correctly if using TLS/SSL. For development, `verify_certs=False` can be used (with caution), or `xpack.security.enabled: false` can be set in `elasticsearch.yml` on the server side (not recommended for production).","message":"Connecting to Elasticsearch 6.x requires careful attention to security settings. By default, recent Elasticsearch versions have security enabled. If connecting to a secure cluster without proper `http_auth`, `api_key`, or `ca_certs` configuration, `SSLError` or `AuthenticationException` will occur.","severity":"gotcha","affected_versions":"All versions of elasticsearch6 client"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure your Elasticsearch 6.x instance is running and accessible. Verify the host and port in your `Elasticsearch` client constructor (e.g., `Elasticsearch('http://localhost:9200')`). Check firewall rules to ensure port 9200 (and 9300 for transport) is open. Use `ping` or `telnet` to confirm network connectivity.","cause":"The Elasticsearch server is not running, is configured on a different host/port, or a firewall is blocking the connection to the specified host and port (default 9200).","error":"elasticsearch.exceptions.ConnectionError: Connection refused"},{"fix":"If you are using `elasticsearch6`, ensure you are actually running an Elasticsearch 6.x server. If you are trying to upgrade to a newer Elasticsearch server (7.x+), you must also upgrade your client to `elasticsearch>=7.0.0` and remove the `doc_type` parameter from your `index`, `get`, and `search` calls, using the typeless endpoints (e.g., `_doc`).","cause":"This error typically occurs when attempting to use a newer version of the `elasticsearch` Python client (e.g., `elasticsearch>=7.0.0`) with code written for Elasticsearch 6.x. The `doc_type` parameter was fully removed in Elasticsearch 7.x+ clients, as Elasticsearch 7+ no longer supports multiple document types per index.","error":"TypeError: index() got an unexpected keyword argument 'doc_type'"},{"fix":"If connecting to an Elastic Cloud instance, ensure you are using a `cloud_id`. For self-managed clusters with TLS, provide the path to your CA certificate bundle via the `ca_certs` parameter in the `Elasticsearch` constructor (e.g., `ca_certs='/path/to/http_ca.crt'`). Alternatively, you can disable certificate verification with `verify_certs=False` (use with extreme caution in production).","cause":"The Python client is attempting to connect to an Elasticsearch instance over HTTPS with an untrusted or improperly configured SSL certificate. By default, `elasticsearch-py` will attempt to verify SSL certificates.","error":"SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:XXXX)"}]}