@@ -167,7 +167,7 @@ with the `security.grant_api_key` API:
167
167
168
168
[source,python]
169
169
------------------------------------
170
- # 8.0+ SUPPORTED USAGES :
170
+ # 8.0+ SUPPORTED USAGE :
171
171
resp = (
172
172
client.options(
173
173
# This is the API key being used for the request
@@ -183,13 +183,36 @@ resp = (
183
183
)
184
184
)
185
185
186
- # 7.x DEPRECATED USAGES (Don't do this!):
186
+ # 7.x DEPRECATED USAGE (Don't do this!):
187
187
resp = (
188
188
# This is the API key being used for the request
189
189
client.security.grant_api_key(
190
190
api_key=("request-id", "request-api-key"),
191
- # This is the API key being granted
192
191
body={
192
+ # This is the API key being granted
193
+ "api_key": {
194
+ "name": "granted-api-key"
195
+ },
196
+ "grant_type": "password",
197
+ "username": "elastic",
198
+ "password": "changeme"
199
+ }
200
+ )
201
+ )
202
+ ------------------------------------
203
+
204
+ Starting with the 8.12 client, using a body parameter is fully supported again, meaning you can also use `grant_api_key` like this:
205
+
206
+ [source,python]
207
+ ------------------------------------
208
+ # 8.12+ SUPPORTED USAGE:
209
+ resp = (
210
+ client.options(
211
+ # This is the API key being used for the request
212
+ api_key=("request-id", "request-api-key")
213
+ ).security.grant_api_key(
214
+ body={
215
+ # This is the API key being granted
193
216
"api_key": {
194
217
"name": "granted-api-key"
195
218
},
@@ -295,7 +318,7 @@ from elasticsearch import TransportError, Elasticsearch
295
318
try:
296
319
client.indices.get(index="index-that-does-not-exist")
297
320
298
- # In elasticsearch-python v7.x this would capture the resulting
321
+ # In elasticsearch-py v7.x this would capture the resulting
299
322
# 'NotFoundError' that would be raised above. But in 8.0.0 this
300
323
# 'except TransportError' won't capture 'NotFoundError'.
301
324
except TransportError as err:
0 commit comments