|
1 |
| -- [User guide of OpenSearch Python Client](#user-guide-of-opensearch-python-client) |
| 1 | +- [User guide of OpenSearch Python client](#user-guide-of-opensearch-python-client) |
2 | 2 | - [Setup](#setup)
|
3 | 3 | - [Example](#example)
|
4 | 4 | - [Creating a client](#creating-a-client)
|
|
9 | 9 | - [Searching for a document](#searching-for-a-document)
|
10 | 10 | - [Deleting a document](#deleting-a-document)
|
11 | 11 | - [Deleting an index](#deleting-an-index)
|
12 |
| - - [Making API Calls](#making-api-calls) |
13 |
| - - [Point in Time API](#point-in-time-api) |
| 12 | + - [Making API calls](#making-api-calls) |
| 13 | + - [Point in time API](#point-in-time-api) |
14 | 14 | - [Using plugins](#using-plugins)
|
15 | 15 | - [Alerting plugin](#alerting-plugin)
|
16 | 16 | - [**Searching for monitors**](#searching-for-monitors)
|
|
22 | 22 | - [Using different authentication methods](#using-different-authentication-methods)
|
23 | 23 | - [Using IAM credentials](#using-iam-credentials)
|
24 | 24 | - [Pre-requisites to use `AWSV4SignerAuth`](#pre-requisites-to-use-awsv4signerauth)
|
| 25 | + - [Using IAM authentication with an async client](#using-iam-authentication-with-an-async-client) |
25 | 26 | - [Using Kerberos](#using-kerberos)
|
26 | 27 |
|
27 | 28 | # User guide of OpenSearch Python client
|
@@ -439,6 +440,51 @@ print('\nSearch results:')
|
439 | 440 | print(response)
|
440 | 441 | ```
|
441 | 442 |
|
| 443 | +## Using IAM authentication with an async client |
| 444 | + |
| 445 | +Make sure to use the `AsyncHttpConnection` connection class with the async `AWSV4SignerAsyncAuth` signer. |
| 446 | + |
| 447 | +```python |
| 448 | +from opensearchpy import OpenSearch, AsyncHttpConnection, AWSV4SignerAsyncAuth |
| 449 | +import boto3 |
| 450 | + |
| 451 | +host = '' # cluster endpoint, for example: my-test-domain.us-east-1.es.amazonaws.com |
| 452 | +region = 'us-west-2' |
| 453 | +credentials = boto3.Session().get_credentials() |
| 454 | +auth = AWSV4SignerAsyncAuth(credentials, region) |
| 455 | +index_name = 'python-test-index3' |
| 456 | + |
| 457 | +client = OpenSearch( |
| 458 | + hosts = [{'host': host, 'port': 443}], |
| 459 | + http_auth = auth, |
| 460 | + use_ssl = True, |
| 461 | + verify_certs = True, |
| 462 | + connection_class = AsyncHttpConnection |
| 463 | +) |
| 464 | + |
| 465 | +async def search(): |
| 466 | + q = 'miller' |
| 467 | + query = { |
| 468 | + 'size': 5, |
| 469 | + 'query': { |
| 470 | + 'multi_match': { |
| 471 | + 'query': q, |
| 472 | + 'fields': ['title^2', 'director'] |
| 473 | + } |
| 474 | + } |
| 475 | + } |
| 476 | + |
| 477 | + response = await client.search( |
| 478 | + body = query, |
| 479 | + index = index_name |
| 480 | + ) |
| 481 | + |
| 482 | + print('\nSearch results:') |
| 483 | + print(response) |
| 484 | + |
| 485 | +search() |
| 486 | +``` |
| 487 | +======= |
442 | 488 | ### Using Kerberos
|
443 | 489 |
|
444 | 490 | There are several python packages that provide Kerberos support over HTTP connections, such as [requests-kerberos](http://pypi.org/project/requests-kerberos) and [requests-gssapi](https://pypi.org/project/requests-gssapi). The following example shows how to setup the authentication. Note that some of the parameters, such as `mutual_authentication` might depend on the server settings.
|
|
0 commit comments