Elasticsearch7にアップデートしました

ごっちの日記
10 min readJun 3, 2019

こんにちは、 .ごっちです。

Railsのプロダクトにいろいろ技術的な挑戦をするために様々とりいれているのですが、少し前にElasticsearchを入れました。

このときは5系だったのですが、7系の最新バージョンにアップグレードしたというお話です。

参考

7系の参考は↑です。

ざっくり開発環境でのアップグレード方法

公式ページからファイルを落としてきます。

起動します。

./elasticsearch-7.1.0/bin/elasticsearch

kuromojiいれます。

$ ./elasticsearch-7.1.0/bin/elasticsearch-plugin install analysis-kuromoji
-> Downloading analysis-kuromoji from elastic
[=================================================] 100%
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.bouncycastle.jcajce.provider.drbg.DRBG (file:/Users/yutagoto/elasticsearch-7.1.0/lib/tools/plugin-cli/bcprov-jdk15on-1.61.jar) to constructor sun.security.provider.Sun()
WARNING: Please consider reporting this to the maintainers of org.bouncycastle.jcajce.provider.drbg.DRBG
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
-> Installed analysis-kuromoji

Gemfile のelasticsearch-rails, elasticsearch-modelのバージョン指定の部分を削除します。

bundle install します。

importします。

$ bin/rails elasticsearch:create_weapon_index
rails aborted!
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Could not convert [name.index] to boolean"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Could not convert [name.index] to boolean","caused_by":{"type":"illegal_argument_exception","reason":"Could not convert [name.index] to boolean","caused_by":{"type":"illegal_argument_exception","reason":"Failed to parse value [analyzed] as only [true] or [false] are allowed."}}},"status":400}
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:202:in `__raise_transport_error'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:319:in `perform_request'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/indices/create.rb:86:in `create'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/bundler/gems/elasticsearch-rails-a67ecc1afc3a/elasticsearch-model/lib/elasticsearch/model/indexing.rb:252:in `create_index!'
/Users/yutagoto/Documents/salmon_run/lib/tasks/elasticsearch.rake:5:in `block (2 levels) in <top (required)>'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/yutagoto/Documents/salmon_run/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => elasticsearch:create_weapon_index
(See full trace by running task with --trace)

なんかエラッたのでindexの修正をします。

# app/models/concerns/weapon_searchable.rb
mappings dynamic: 'false' do
indexes 'name', analyzer: 'kuromoji_analyzer'
end

これでインポートタスクを実行させると無事に完了します。

これに合わせてテストやCircleCIの設定も変更しています。

詳しい差分はしたのPRを見てください。

そんなこんなで動かしてみたお話でした。このくらいの規模ならいらないといえばいらないんですが念の為。。

--

--