OpenSearch Service クラスターにインデックスパターンを作成する方法を教えてください。
Amazon OpenSearch Service クラスターにインデックスパターンを作成したいと考えています。
解決策
前提条件:
- AWS Identity and Access Management (IAM) ユーザーには、インデックスパターンを作成するための PUT、POST 権限が付与されていること。アクセスポリシーの例:
注: region を AWS リージョンに、account-id を AWS アカウントに、domain-name をドメイン名に置き換えてください。{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "es:ESHttpHead", "es:ESHttpPost", "es:ESHttpGet", "es:ESHttpDelete", "es:ESHttpPut" ], "Resource": "arn:aws:es:region:account-id:domain/domain-name/*" } ] } - インデックスパターンが許可されているクラスターバージョンが必要です。
インデックスパターンを作成する
OpenSearch Dashboards を使用する
OpenSearch Dashboards を使用すると、詳細アクセス制御 (FGAC) が有効または無効な状態で OpenSearch Service または Elasticsearch クラスター用のインデックスパターンを作成できます。手順については、OpenSearch のウェブサイトで「インデックスパターンの作成」を参照してください。
curl コマンドを使用する
詳細アクセス制御を使用せずクラスターのインデックスパターンを作成するには、次のコマンドをクラスタータイプに応じて実行します。
Elasticsearch クラスター:
curl -X POST https://elasticsearch-end-point/_plugin/kibana/api/saved_objects/index-pattern/ \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{ "attributes": { "title": "sample-index*" } }'
注: sample-index を目的のインデックス名またはパターンに置き換えてください。
OpenSearch サービスクラスター:
curl -X POST https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/ \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{ "attributes": { "title": "sample-index*" } }'
注: sample-index を目的のインデックス名またはパターンに置き換えてください。
クラスターで詳細アクセス制御を使用する場合は、次の手順を実行します。
- 認証 Cookie を auth.txt ファイルに生成するには、クラスタータイプに応じて次のコマンドを実行します。
Elasticsearch クラスター:
注: usernameexample をユーザー名に、passwordexample をパスワードに置き換えてください。curl -X POST https://elasticsearch-end-point/_plugin/kibana/auth/login \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{"username":"usernameexample", "password":"passwordexample"}' \ -c auth.txt
OpenSearch サービスクラスター:
注: usernameexample をユーザー名に、passwordexample をパスワードに置き換えてください。curl -X POST https://opensearch-end-point/_dashboards/auth/login \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{"username":"usernameexample", "password":"passwordexample"}' \ -c auth.txt - インデックスパターンの作成リクエストを送信するには、クラスタータイプに応じて次のコマンドを実行します。
Elasticsearch クラスター:
注: sample-index を目的のインデックス名またはパターンに置き換えてください。curl -X POST https://elasticsearch-end-point/_plugin/kibana/api/saved_objects/index-pattern/test \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{ "attributes": { "title": "sample-index*" } }' \ -b auth.txt
OpenSearch サービスクラスター:
注: sample-index を目的のインデックス名またはパターンに置き換えてください。curl -X POST https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/ \ -H "kbn-xsrf: true" \ -H "content-type: application/json" \ -d '{ "attributes": { "title": "sample-index*" } }' \ -b auth.txt
Python を使用する
前提条件:
- Python コードを実行するロールを、FGAC クラスターのバックエンドロールにマッピングすること。
- 必要な依存関係をインストールするには、次のコマンドを実行します。
pip install boto3 pip install opensearch-py pip install requests pip install requests-aws4auth
OpenSearch サービスクラスターのインデックスパターンを作成するには、次の Python コマンドを実行します、。
import boto3 import requests from requests_aws4auth import AWS4Auth host = 'https://domain-endpoint/' # include trailing / region = 'aos-region' # example us-west-1 service = 'es' credentials = boto3.Session().get_credentials() awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token) path = '_dashboards/api/saved_objects/index-pattern' # _plugin/kibana/api/saved_objects/index-pattern for es versions url = host + path payload = {"attributes":{"title":"multi-logs-*","fields":"[]"}} headers = {"Content-Type": "application/json", "osd-xsrf": "true", "security_tenant": "global" } r = requests.post (url, auth=awsauth, json=payload, headers=headers) print(r.status_code) print(r.text)
注: domain-endpoint をドメインエンドポイントに、aos-region をリージョンに置き換えてください。Elasticsearch クラスターでは、_dashboards/api/saved_objects/index-pattern を _plugin/kibana/api/saved_objects/index-pattern に置き換えてください。
インデックスパターン作成に関する問題のトラブルシューティング
SAML 2.0 または Amazon Cognito 認証で詳細アクセス制御を使用している
クラスターのドメインが認証に SAML 2.0 または Amazon Cognito を使用している場合は、インデックスパターンを管理する内部ユーザーを作成します。
注: 詳細アクセス制御が有効なクラスターでは、ユーザーがインデックスパターンを作成するには、ESHttpPut、ESHttpPost の各権限が必要です。
グローバルテナントにインデックスパターンを作成できない
デフォルト動作として、OpenSearch Dashboards は、グローバルテナントにインデックスパターンを作成します。グローバルテナントの外部でインデックスパターンを作成するには、次のコマンドを実行します。
curl -s -X POST https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/sample-index -d '{"attributes": {"title": "sample-index*"}}' \ -H "osd-xsrf:true" \ -H "securitytenant: private" \ -H "content-type:application/json" \ -b auth.txt
注: sample-index を目的のインデックス名またはパターンに置き換えてください。
.kibana エイリアスがクラスターに含まれていない
この問題をトラブルシューティングするには、次の手順を実行します。
- .kibana エイリアスがクラスターに存在するかどうかを確認するには、次のコマンドを実行します。
注: 詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。コマンド例:curl -XGET https://opensearch-end-point/_cat/aliases
.kibana インデックスが存在しない場合は、ステップ 4 に進みます。curl -XPOST -u 'master-user:master-user-password' 'domain-endpoint/_cat/indices - .kibana インデックスのバックアップを作成するには、次のコマンドを実行します。
注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。curl -XPOST "https://domain-endpoint/_reindex" -H 'Content-Type: application/json' -d'{ "source": { "index": ".kibana" }, "dest": { "index": ".kibana_backup" } }' - .kibana インデックスを削除するには、次のコマンドを実行します。
注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。curl -XDELETE "https://domain-endpoint/.kibana" - .kibana エイリアスを作成し、インデックス .kibana_backup を指すよう設定するには、次のコマンドを実行します。
注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。curl -XPOST "https://domain-endpoint/_aliases" -H 'Content-Type: application/json' -d'{ "actions": [ { "add": { "index": ".kibana_backup", "alias": ".kibana" } } ] }'
関連情報
OpenSearch Service で Kibana ダッシュボードをエクスポート、インポートする
ISM ポリシーのロールオーバーインデックスアクションが OpenSearch Service で継続的に失敗する原因を教えてください

