3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elastic社のElastic Cloudで、Elasticsearchサーバーに対してCORSを設定する

Last updated at Posted at 2020-10-07

Elasticsearchで試していると、ひとまず手取り早く試したいという時がくると思います。
その時のメモです。

Elastic社のElastic Cloudに作成したElasticsearchに対して、直接クエリを投げるWebアプリを(テスト的に)作った際に、デフォルトの設定のままではCORSの制限に引っかかります。

スクリーンショット 2020-10-07 23.17.25.png

以下ドキュメントから
Add Elasticsearch user settings | Elasticsearch Service Documentation | Elastic

1. Log in to the Elasticsearch Service Console.

2. Select your deployment on the home page in the Elasticsearch Service card or go to the deployments page.

3. From your deployment menu, go to the Edit page.

4. At the bottom of each Elasticsearch node, expand the User settings overrides caret.

スクリーンショット 2020-10-07 23.20.04.png

5. Update the user settings.

開いたエディタ部分にHTTPの設定を入れる

http:
  cors.enabled: true
  cors.allow-origin: /https?:\/\/(localhost(:[0-9]+)?|xxxxx.github.io)/
  cors.allow-methods: GET
  cors.allow-headers: Authorization, X-Requested-With,X-Auth-Token,Content-Type, Content-Length

※以下の2つからのアクセスを許可する設定にしています。

  • localhost
  • xxxxx.github.io

スクリーンショット 2020-10-07 23.21.35.png

6. Click Save changes.

スクリーンショット 2020-10-07 23.23.50.png

Saveボタンを押すとサーバーの更新が始まります。

スクリーンショット 2020-10-07 23.28.57.png

ローディングが終わったら設定が反映されています。

スクリーンショット 2020-10-07 23.39.20.png

コンソールログにもエラーは出なくなりました。

スクリーンショット 2020-10-07 23.29.49.png

参考

Add Elasticsearch user settings | Elasticsearch Service Documentation | Elastic

HTTP | Elasticsearch Reference [7.9] | Elastic

YML 設定 - Elasticsearch インスタンス| Alibaba Cloud ドキュメントセンター

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?