

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon OpenSearch Service クエリへのプラグインの適用
<a name="managed-apply-plugin"></a>

[パイプラインを作成](managed-opensearch-plugin-pipeline-example.md)したら、Amazon Personalize Search Ranking プラグインをクエリに適用する準備が整います。Amazon Personalize Search Ranking プラグインは、インデックスのすべてのクエリとレスポンスに適用できます。このプラグインは個々のクエリとレスポンスにも適用できます。
+  次の Python コードを使用して、検索パイプラインをインデックスに適用できます。この方法では、このインデックスを使用するすべての検索で、プラグインを使用して検索結果にパーソナライゼーションを適用します。

  ```
  import requests
  from requests_auth_aws_sigv4 import AWSSigV4
  
  domain_endpoint = 'domain endpoint'
  index = 'index name'
  url = f'{domain_endpoint}/{index}/_settings/'
  auth = AWSSigV4('es')
  headers = {'Content-Type': 'application/json'}
  body = {
      "index.search.default_pipeline": "pipeline name"
  }
  try:
      response = requests.put(url, auth=auth, json=body, headers=headers)
      print(response.text)
  except Exception as e:
      print(f"Error: {e}")
  ```
+ 次の Python コードを使用して、トヨタブランドの自動車の個別のクエリに検索パイプラインを適用できます。

  コードを更新して、ドメインエンドポイント、OpenSearch Service インデックス、パイプラインの名前、クエリを指定します。`user_id` には、検索結果を取得するユーザーの ID を指定します。Amazon Personalize ソリューションバージョンの作成に使用したデータに、このユーザーが存在する必要があります。ユーザーが不在の場合、Amazon Personalize は人気に基づいてアイテムをランク付けします。

  `context` には、コンテキストメタデータを使用する場合は、デバイスタイプなどのユーザーのコンテキストメタデータを提供してください。`context` フィールドはオプションです。詳細については、「[コンテキストメタデータを使用したレコメンデーションの関連性の向上](contextual-metadata.md)」を参照してください。

  ```
  import requests
  from requests_auth_aws_sigv4 import AWSSigV4
  
  domain_endpoint = 'domain endpoint'
  index = 'index name'
  url = f'{domain_endpoint}/{index}/_search/'
  
  auth = AWSSigV4('es')
  headers = {'Content-Type': 'application/json'}
  params = {"search_pipeline": "pipeline-name"}
  body = {
      "query": {
          "multi_match": {
              "query": "Toyota",
              "fields": ["BRAND"]
          }
      },
      "ext": {
          "personalize_request_parameters": {
              "user_id": "USER ID",
              "context": { "DEVICE" : "mobile phone" }
          }
      }
  }
  try:
      response = requests.post(url, auth=auth, params=params, json=body, headers=headers, verify=False)
      print(response)
  except Exception as e:
      print(f"Error: {e}")
  ```