sorta kinda...

主にAWS関連ですが、これに限らずいろいろ勉強したことや思ったことを書いていきます。

Curator を使って elasticsearch に何かする [cloudpack OSAKA blog]

ナスです。

先日、こんな記事を書きました。
nasrinjp1.hatenablog.com

この中で、Curator の Amazon ES のサポートが微妙って書いたんですが、でもやっぱり楽したいですし、あるものはパクろうの精神で実際に試してみました。

 

インストール

今回は自分の mac に入れてみました。pip で入れるので、環境が変わっても手順は同じです。バージョン4は Amazon ES のサポートが No となっていたので、3 の最新を入れました。

$ pip install 'elasticsearch-curator<4.0'
Collecting elasticsearch-curator<4.0
  Downloading elasticsearch_curator-3.5.1-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 1.5MB/s
Collecting elasticsearch<3.0.0,>=2.3.0 (from elasticsearch-curator<4.0)
  Downloading elasticsearch-2.4.1-py2.py3-none-any.whl (55kB)
    100% |████████████████████████████████| 61kB 2.8MB/s
Collecting click>=3.3 (from elasticsearch-curator<4.0)
  Downloading click-6.7-py2.py3-none-any.whl (71kB)
    100% |████████████████████████████████| 71kB 2.0MB/s
Requirement already satisfied: urllib3<2.0,>=1.8 in /Library/Python/2.7/site-packages (from elasticsearch<3.0.0,>=2.3.0->elasticsearch-curator<4.0)
Installing collected packages: elasticsearch, click, elasticsearch-curator
  Found existing installation: elasticsearch 5.3.0
    Uninstalling elasticsearch-5.3.0:
      Successfully uninstalled elasticsearch-5.3.0
Successfully installed click-6.7 elasticsearch-2.4.1 elasticsearch-curator-3.5.1

$ curator --version
curator, version 3.5.1

 

インデックス一覧取得

インデックス一覧を取ってみました。この例は、作成されてから 1 日以上経過したインデックスだけを取ります。1 個しか作ってないので、一覧と言っても 1 個だけ表示されてます。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 --debug show indices --older-than 1 --time-unit days --timestring %Y.%m.%d
2017-04-05 10:11:04,901 INFO      Job starting: show indices
2017-04-05 10:11:05,046 INFO      Action show will be performed on the following indices: [u'cwl-test-2017.04.01']
2017-04-05 10:11:05,046 INFO      Matching indices:
cwl-test-2017.04.01

–debug をつけると詳細が見れます。なんか WARNING が出てますが、/cluster/state/metadata へのアクセスは AWS から許可されていないので、これが出ています。いろいろやってみてわかったんですが、どんな操作をしても、Curator は /cluster/state/metadata にアクセスしています。たぶんどうにもなりません。

2017-04-05 10:52:45,008 WARNING            elasticsearch       log_request_fail:88   GET /_cluster/state/metadata/cwl-test-2017.04.01 [status:401 request:0.030s]

■サポートされるオペレーション docs.aws.amazon.com

 

インデックスの close

closeは、削除はしないけど検索対象から外す(隠す)ってことっぽいです。
www.elastic.co

で、試してみたんですが、なんかエラー出ました。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 close indices --older-than 1 --time-unit days --timestring %Y.%m.%d
Error closing indices.  Run with --debug flag and/or check Elasticsearch logs for more information.

–debug つけてやってみると、エラーの原因が出ました。単に AWS が /_close に対するアクセスを許可してなかっただけでした。サポートされるオペレーションの中にも確かになかったです。

2017-04-05 10:15:41,716 WARNING            elasticsearch       log_request_fail:88   POST /cwl-test-2017.04.01/_close?ignore_unavailable=true [status:401 request:0.030s]
2017-04-05 10:15:41,716 DEBUG              elasticsearch       log_request_fail:99   < {"Message":"Your request: '/cwl-test-2017.04.01/_close' is not allowed by Amazon Elasticsearch Service."}

 

インデックス削除

インデックスの削除は問題なくできました。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 --debug delete indices --older-than 1 --time-unit days --timestring %Y.%m.%d
2017-04-05 10:20:41,340 INFO      Job starting: delete indices
2017-04-05 10:20:41,451 INFO      Pruning Kibana-related indices to prevent accidental deletion.
2017-04-05 10:20:41,451 INFO      Action delete will be performed on the following indices: [u'cwl-test-2017.04.01']
2017-04-05 10:20:41,520 INFO      Deleting indices as a batch operation:
2017-04-05 10:20:41,520 INFO      ---deleting index cwl-test-2017.04.01
2017-04-05 10:20:41,600 INFO      Job completed successfully.

 

というわけで、インデックスのハウスキープ処理をするだけなら Curator を使えば ok ってことですね。次に機会があったら使ってみようと思います。