翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Amazon OpenSearch サービスでの HTTP リクエストの圧縮
Amazon OpenSearch サービスドメイン内の HTTP リクエストとレスポンスは、gzip 圧縮を使用して圧縮できます。gzip 圧縮を使用すると、ドキュメントのサイズを縮小し、帯域幅の使用率とレイテンシーを低減できるため、転送速度が向上します。
Gzip 圧縮は、Elasticsearch 6.0 OpenSearch 以降を実行しているすべてのドメインでサポートされています。 OpenSearch 一部のクライアントには gzip 圧縮のサポートが組み込まれており、多くのプログラミング言語にはプロセスを簡略化するライブラリがあります。
gzip 圧縮を有効にする
OpenSearch 同様の設定と混同しないでください。 OpenSearch Service http_compression.enabled
固有のもので、ドメインで gzip 圧縮を有効または無効にします。Elasticsearch 7 OpenSearch を実行しているドメイン。 x では gzip 圧縮がデフォルトで有効になっているのに対し、Elasticsearch 6 を実行しているドメインでは gzip 圧縮が有効になっています。 x ではデフォルトで無効になっています。
gzip 圧縮を有効にするには、次のリクエストを送信します。
PUT _cluster/settings { "persistent" : { "http_compression.enabled": true } }
_cluster/settings
へのリクエストは圧縮解除する必要があるので、クラスター設定を更新するために別のクライアントまたは標準の HTTP 要求を使用する必要がある場合があります。
gzip 圧縮が正常に有効になったことを確認するには、以下のリクエストを送信してください。
GET _cluster/settings?include_defaults=true
レスポンスに次の設定が表示されることを確認してください。
... "http_compression": { "enabled": "true" } ...
必要なヘッダー
gzip 圧縮されたリクエストボディを含める場合は、標準の Content-Type:
application/json
ヘッダーを保持し、Content-Encoding: gzip
ヘッダーを追加します。gzip 圧縮レスポンスを受け入れるには、Accept-Encoding: gzip
ヘッダーも同様に追加します。 OpenSearch クライアントが gzip 圧縮をサポートしている場合、これらのヘッダーは自動的に含まれる可能性があります。
サンプルコード (Python 3)
次のサンプルでは、opensearch-py
from opensearchpy import OpenSearch, RequestsHttpConnection from requests_aws4auth import AWS4Auth import boto3 host = '' # e.g. my-test-domain.us-east-1.es.amazonaws.com region = '' # e.g. us-west-1 service = 'es' credentials = boto3.Session().get_credentials() awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token) # Create the client. search = OpenSearch( hosts = [{'host': host, 'port': 443}], http_auth = awsauth, use_ssl = True, verify_certs = True, http_compress = True, # enables gzip compression for request bodies connection_class = RequestsHttpConnection ) document = { "title": "Moneyball", "director": "Bennett Miller", "year": "2011" } # Send the request. print(search.index(index='movies', id='1', body=document, refresh=True)) # print(search.index(index='movies', doc_type='_doc', id='1', body=document, refresh=True))
あるいは、適切なヘッダーを指定し、リクエストボディを自身で圧縮し、リクエスト
import requests import gzip import json base_url = '' # The domain with https:// and a trailing slash. For example, https://my-test-domain.us-east-1.es.amazonaws.com/ auth = ('
master-user
', 'master-user-password
') # For testing only. Don't store credentials in code. headers = {'Accept-Encoding': 'gzip', 'Content-Type': 'application/json', 'Content-Encoding': 'gzip'} document = { "title": "Moneyball", "director": "Bennett Miller", "year": "2011" } # Compress the document. compressed_document = gzip.compress(json.dumps(document).encode()) # Send the request. path = 'movies/_doc?refresh=true' url = base_url + path response = requests.post(url, auth=auth, headers=headers, data=compressed_document) print(response.status_code) print(response.text)