スキップしてコンテンツを表示

OpenSearch Service クラスターにインデックスパターンを作成する方法を教えてください。

所要時間3分
0

Amazon OpenSearch Service クラスターにインデックスパターンを作成したいと考えています。

解決策

前提条件:

  • AWS Identity and Access Management (IAM) ユーザーには、インデックスパターンを作成するための PUT、POST 権限が付与されていること。アクセスポリシーの例:
    {  "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/*"
        }
      ]
    }
    注: region を AWS リージョンに、account-id を AWS アカウントに、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 を目的のインデックス名またはパターンに置き換えてください。

クラスターで詳細アクセス制御を使用する場合は、次の手順を実行します。

  1. 認証 Cookie を auth.txt ファイルに生成するには、クラスタータイプに応じて次のコマンドを実行します。
    Elasticsearch クラスター:
    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
    注: usernameexample をユーザー名に、passwordexample をパスワードに置き換えてください。
    OpenSearch サービスクラスター:
    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
    注: usernameexample をユーザー名に、passwordexample をパスワードに置き換えてください。
  2. インデックスパターンの作成リクエストを送信するには、クラスタータイプに応じて次のコマンドを実行します。
    Elasticsearch クラスター:
    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
    注: 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*" } }' \
    -b auth.txt
    注: sample-index を目的のインデックス名またはパターンに置き換えてください。

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 を使用している場合は、インデックスパターンを管理する内部ユーザーを作成します。

注: 詳細アクセス制御が有効なクラスターでは、ユーザーがインデックスパターンを作成するには、ESHttpPutESHttpPost の各権限が必要です。

グローバルテナントにインデックスパターンを作成できない

デフォルト動作として、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 エイリアスがクラスターに含まれていない

この問題をトラブルシューティングするには、次の手順を実行します。

  1. .kibana エイリアスがクラスターに存在するかどうかを確認するには、次のコマンドを実行します。
    curl -XGET https://opensearch-end-point/_cat/aliases
    注: 詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。コマンド例:
    curl -XPOST -u 'master-user:master-user-password' 'domain-endpoint/_cat/indices
    .kibana インデックスが存在しない場合は、ステップ 4 に進みます。
  2. .kibana インデックスのバックアップを作成するには、次のコマンドを実行します。
    curl -XPOST "https://domain-endpoint/_reindex" -H 'Content-Type: application/json' -d'{
      "source": {
        "index": ".kibana"
      },
      "dest": {
     "index": ".kibana_backup"
      }
    }'
    注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。
  3. .kibana インデックスを削除するには、次のコマンドを実行します。
    curl -XDELETE "https://domain-endpoint/.kibana"
    注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。
  4. .kibana エイリアスを作成し、インデックス .kibana_backup を指すよう設定するには、次のコマンドを実行します。
    curl -XPOST "https://domain-endpoint/_aliases" -H 'Content-Type: application/json' -d'{
      "actions": [
        {
          "add": {
            "index": ".kibana_backup",
            "alias": ".kibana"
          }
        }
      ]
    }'
    注: DOMAIN_ENDPOINT をドメインエンドポイントに置き換えてください。詳細アクセス制御を使用するクラスターでは、ユーザー名とパスワードに -u フラグを指定します。

関連情報

OpenSearch Service で Kibana ダッシュボードをエクスポート、インポートする

ISM ポリシーのロールオーバーインデックスアクションが OpenSearch Service で継続的に失敗する原因を教えてください

AWS公式更新しました 3ヶ月前
コメントはありません

関連するコンテンツ