Skip to content

Commit 4601f82

Browse files
add migrated files
1 parent e76bf7e commit 4601f82

28 files changed

+4489
-0
lines changed

docs/docset.yml

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.

docs/images/create-api-key.png

78.7 KB
Loading

docs/images/es-endpoint.jpg

361 KB
Loading

docs/images/otel-waterfall-retry.png

49.5 KB
Loading
43.2 KB
Loading
34.9 KB
Loading

docs/reference/_configuration.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/_configuration.html
4+
---
5+
6+
# Configuration [_configuration]
7+
8+
There are several ways to configure connections for the library. The easiest and most useful approach is to define one default connection that can be used every time an API call is made without explicitly passing in other connections.
9+
10+
::::{note}
11+
Unless you want to access multiple clusters from your application, it is highly recommended that you use the `create_connection` method and all operations will use that connection automatically.
12+
13+
::::
14+
15+
16+
## Default connection [_default_connection]
17+
18+
To define a default connection that can be used globally, use the `connections` module and the `create_connection` method like this:
19+
20+
```python
21+
from elasticsearch.dsl import connections
22+
23+
connections.create_connection(hosts=['localhost'], timeout=20)
24+
```
25+
26+
### Single connection with an alias [_single_connection_with_an_alias]
27+
28+
You can define the `alias` or name of a connection so you can easily refer to it later. The default value for `alias` is `default`.
29+
30+
```python
31+
from elasticsearch.dsl import connections
32+
33+
connections.create_connection(alias='my_new_connection', hosts=['localhost'], timeout=60)
34+
```
35+
36+
Additional keyword arguments (`hosts` and `timeout` in our example) will be passed to the `Elasticsearch` class from `elasticsearch-py`.
37+
38+
To see all possible configuration options refer to the [documentation](https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html).
39+
40+
41+
42+
## Multiple clusters [_multiple_clusters]
43+
44+
You can define multiple connections to multiple clusters at the same time using the `configure` method:
45+
46+
```python
47+
from elasticsearch.dsl import connections
48+
49+
connections.configure(
50+
default={'hosts': 'localhost'},
51+
dev={
52+
'hosts': ['esdev1.example.com:9200'],
53+
'sniff_on_start': True
54+
}
55+
)
56+
```
57+
58+
Such connections will be constructed lazily when requested for the first time.
59+
60+
You can alternatively define multiple connections by adding them one by one as shown in the following example:
61+
62+
```python
63+
# if you have configuration options to be passed to Elasticsearch.__init__
64+
# this also shows creating a connection with the alias 'qa'
65+
connections.create_connection('qa', hosts=['esqa1.example.com'], sniff_on_start=True)
66+
67+
# if you already have an Elasticsearch instance ready
68+
connections.add_connection('another_qa', my_client)
69+
```
70+
71+
### Using aliases [_using_aliases]
72+
73+
When using multiple connections, you can refer to them using the string alias specified when you created the connection.
74+
75+
This example shows how to use an alias to a connection:
76+
77+
```python
78+
s = Search(using='qa')
79+
```
80+
81+
A `KeyError` will be raised if there is no connection registered with that alias.
82+
83+
84+
85+
## Manual [_manual]
86+
87+
If you don’t want to supply a global configuration, you can always pass in your own connection as an instance of `elasticsearch.Elasticsearch` with the parameter `using` wherever it is accepted like this:
88+
89+
```python
90+
s = Search(using=Elasticsearch('localhost'))
91+
```
92+
93+
You can even use this approach to override any connection the object might be already associated with:
94+
95+
```python
96+
s = s.using(Elasticsearch('otherhost:9200'))
97+
```
98+
99+
::::{note}
100+
When using the `dsl` module, it is highly recommended that you use the built-in serializer (`elasticsearch.dsl.serializer.serializer`) to ensure your objects are correctly serialized into `JSON` every time. The `create_connection` method that is described here (and that the `configure` method uses under the hood) will do that automatically for you, unless you explicitly specify your own serializer. The built-in serializer also allows you to serialize your own objects - just define a `to_dict()` method on your objects and that method will be automatically called when serializing your custom objects to `JSON`.
101+
102+
::::
103+
104+
105+

docs/reference/_examples.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/_examples.html
4+
---
5+
6+
# Examples [_examples]
7+
8+
Please see the [DSL examples](https://github.com/elastic/elasticsearch-py/tree/master/examples/dsl) directory to see some complex examples using the DSL module.
9+

0 commit comments

Comments
 (0)