参考 : https://opensearch.org/docs/latest/getting-started/communicate/
REST APIまたはプログラミング言語のどれかを使用して、OpenSearchと通信できます。 プログラミング言語でOpenSearchと通信する必要がある場合は、利用可能なクライアントのリストについては、クライアントセクションを参照してください。
OpenSearch REST APIと通信する
REST APIを使用してOpenSearchクラスターと疎通することができます。 例えば、Curlなどのクライアントや、HTTPリクエストを送信できるプログラミング言語を使用することでOpensearchからデータを取得できます。
Opensearchへcurlコマンドを使用してリクエストを送信
Opensearchのエンドポイントへヘルスチェックを行うためには、 _cluster/health
にGETメソッドでアクセスします。
curl -XGET "http://localhost:9200/_cluster/health"
サンプル実行結果
{ "cluster_name": "opensearch-cluster", "status": "yellow", "timed_out": false, "number_of_nodes": 1, "number_of_data_nodes": 1, "discovered_master": true, "discovered_cluster_manager": true, "active_primary_shards": 8, "active_shards": 8, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 1, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 88.88888888888889 }
必要な場合はリクエストパラメーターにユーザー名とパスワードを入れてください。
curl -X GET "http://localhost:9200/_cluster/health" -ku admin:あなたが設定したパスワード
OpenSearchは通常、デフォルトではJSON形式で応答を返します。
プログラムの読み取りではなくデバッグを意図とした人間が読む場合、?pretty
を使用してより見やすく出力できます。
curl -XGET "http://localhost:9200/_cluster/health?pretty"
bodyを含むリクエストについては、コンテンツタイプのヘッダーをapplication/json
に設定し、-d(data)オプションでリクエストボディを指定します。
curl -XGET "http://localhost:9200/students/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "match_all": {} } }'