とーますメモ

Ruby on Rails / Goなどの学習メモ

【Elasticsearch】5.x系でElasticsearch-headを使う時の注意点

既に色んなサイトにも載っているが、
5.x系でElasticsearch-headを使用する場合は、プラグインとしてではなく
1つのスタンドアローンサーバとして使用する事になる。

ローカル環境で使用するため、
公式サイトの説明通りに、まずはインストールする。

環境設定

インストール

$ git clone git://github.com/mobz/elasticsearch-head.git
$ cd elasticsearch-head
$ npm install

起動

npm run start

確認

「http://localhost:9100/」を開く。

※Elasticsearchは「localhost:9200」で動作している前提

注意点

さて、上記の設定のままlocalhost:9200にアクセスすると
elasticsearch-headのページ自体は確認できるが

「cluster health: not connected」

と表示されたのではないだろうか。

実は、別途elasticsearch.yml内に
以下の追加設定をする必要がある。

http.cors.enabled: true
http.cors.allow-origin: "*"

以下公式サイトの引用。

Enable CORS in elasticsearch

When not running as a plugin of elasticsearch (which is not even possible from version 5) you must enable CORS in elasticsearch otherwise your browser will rejects requests which appear insecure.


In elasticsearch configuration;

add http.cors.enabled: true
you must also set http.cors.allow-origin because no origin allowed by default. http.cors.allow-origin: "*" is valid value, however it’s considered as a security risk as your cluster is open to cross origin from anywhere.

github.com

最後の一文にもあるが、http.cors.allow-origin: "*"の設定は
どこからでも接続を許可するという設定であり
セキュリティ的にリスクがあるため、扱いには注意が必要。