Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 76 additions & 23 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,75 @@ mapped_pages:

This documentation covers the [official Python client for {{es}}](https://github.com/elastic/elasticsearch-py). The goal of the Python client is to provide common ground for all {{es}}-related code in Python. The client is designed to be unopinionated and extendable.

API reference documentation is provided on [Read the Docs](https://elasticsearch-py.readthedocs.io).
## Example [_example]

::::{tab-set}

The following example shows a simple Python client use case:
:::{tab-item} Standard Python
```python
import os
from elasticsearch import Elasticsearch

def main():
client = Elasticsearch(
hosts=[os.getenv("ELASTICSEARCH_URL")],
api_key=os.getenv("ELASTIC_API_KEY"),
)

resp = client.search(
index="my-index-000001",
from_="40",
size="20",
query={
"term": {
"user.id": "kimchy"
}
},
)
print(resp)
```
:::

:::{tab-item} Async Python
```python
>>> from datetime import datetime
>>> from elasticsearch import Elasticsearch
import os
from elasticsearch import AsyncElasticsearch

async def main():
client = AsyncElasticsearch(
hosts=[os.getenv("ELASTICSEARCH_URL")],
api_key=os.getenv("ELASTIC_API_KEY"),
)

resp = await client.search(
index="my-index-000001",
from_="40",
size="20",
query={
"term": {
"user.id": "kimchy"
}
},
)
print(resp)
```
:::

# Connect to 'http://localhost:9200'
>>> client = Elasticsearch("http://localhost:9200")
::::

# Datetimes will be serialized:
>>> client.index(index="my-index-000001", id=42, document={"any": "data", "timestamp": datetime.now()})
{'_id': '42', '_index': 'my-index-000001', '_type': 'test-type', '_version': 1, 'ok': True}
## Overview [_overview]

# ...but not deserialized
>>> client.get(index="my-index-000001", id=42)['_source']
{'any': 'data', 'timestamp': '2013-05-12T19:45:31.804229'}
```
This package is composed of several modules:

### The actual client

This module, sometimes also called the "low-level" client, implements the support for sending requests to {{es}} servers. The client provides access to the entire surface of the {{es}} API.

* [Getting Started guide](getting-started.md)
* [Ingest data with Python walkthrough](docs-content://manage-data/ingest/ingesting-data-from-applications/ingest-data-with-python-on-elasticsearch-service.md)
* [Reference documentation](https://elasticsearch-py.readthedocs.io/en/stable/es_api.html)

## Features [_features]
#### Features [_features]

The client's features include:

Expand All @@ -45,19 +89,28 @@ The client's features include:
* Thread safety
* Pluggable architecture

The client also provides a convenient set of [helpers](client-helpers.md) for tasks like bulk indexing and reindexing.
### Bulk helpers

::::{tip}
To get started, try this walkthrough: [Ingest data with Python](docs-content://manage-data/ingest/ingesting-data-from-applications/ingest-data-with-python-on-elasticsearch-service.md)
::::
The bulk helpers are a set of functions that simplify the ingest of large amounts of data through a high-level interface based on Python iterables.

* [User guide](client-helpers.md#bulk-helpers)
* [Reference documentation](https://elasticsearch-py.readthedocs.io/en/stable/api_helpers.html)

### ES|QL query builder

### Elasticsearch Python DSL [_elasticsearch_python_dsl]
This module offers an idiomatic interface to construct ES|QL queries using Python expressions.

The [Python DSL module](../reference/elasticsearch-dsl.md) offers a convenient and idiomatic way to write and manipulate queries.
* [User guide](esql-query-builder.md)
* [Reference documentation](https://elasticsearch-py.readthedocs.io/en/stable/esql.html)

## {{es}} version compatibility [_compatibility]
### DSL module

Language clients are **forward compatible**: each client version works with equivalent and later minor versions of the **same or next major** version of {{es}}. For full compatibility, the client and {{es}} minor versions should match.
The DSL module could be thought of as a "high-level" client for {{es}}. It allows applications to manipulate documents and queries using Python classes and objects instead of primitive types such as dictionaries and lists.

* [User guide](elasticsearch-dsl.md)
* [Reference documentation](https://elasticsearch-py.readthedocs.io/en/stable/dsl.html)

## Compatibility [_compatibility]

| Client version | {{es}} `8.x` | {{es}} `9.x` | {{es}} `10.x` |
|----------------|---------------------------------|---------------------------------|----------------------------------|
Expand All @@ -82,4 +135,4 @@ In the Python client, compatibility mode is always enabled.

:::{tip}
To support working with multiple client versions, the Python client is also released under the package names `elasticsearch8` and `elasticsearch9` (to prevent name collisions).
:::
:::