背景
OpenSearchのPainless scriptを利用することで重い処理を意図的に行いスローログを出力できるかテストしようとした
その際に大量のドキュメントが含まれたインデックスが必要だった
その大量のドキュメントをサンプルとして生成できる方法があったので紹介
環境
AWS OpenSearch 2.3
CUIの踏み台はAmazonLinux2を使用
curl 7.84
ポイント
CUIの場合OpenSearch Dashboards APIを使用するためにまずクッキーを取得する必要がある
やってみた
GUI ver
Sample web logs > Add data をクリック
CUI ver
踏み台EC2からパスワード認証で実施した
auth.txtにクッキー情報がある
curl -k -X POST https://opensearch.local/_dashboards/auth/login \
-H "osd-xsrf: true" \
-H "content-type:application/json" \
-d '{"username":"<ユーザ名>", "password":"<パスワード>"}' \
-c auth.txt
curl -k -X POST https://opensearch.local/_dashboards/api/sample_data/logs \
-H "osd-xsrf:true" \
-H "content-type:application/json" \
-b auth.txt
osd-xsrf: true をヘッダーに追加しない場合、下記のエラーが生じますので注意
{"status": 400, "body": "Request must contain a osd-xsrf header."}
参考資料
[1] Quickstart guide for OpenSearch Dashboards - OpenSearch documentation
https://opensearch.org/docs/latest/dashboards/quickstart-dashboards/
[2] Requests to OpenSearch Dashboards fail with “Request must contain a osd-xsrf header” | Common issues - OpenSearch documentation
https://opensearch.org/docs/2.0/troubleshoot/index/#requests-to-opensearch-dashboards-fail-with-request-must-contain-a-osd-xsrf-header
[3] Set advanced settings with the Amazon OpenSearch Service Dashboards API | AWS Big Data Blog
https://aws.amazon.com/blogs/big-data/set-advanced-settings-with-the-amazon-opensearch-service-dashboards-api/