Homeland ElasticSearch Error

dailyzhou · 2019年06月14日 · 最后由 dailyzhou 回复于 2019年10月18日 · 6607 次阅读

版本升级的时候遇到个重建索引的错,现象是现在网站无法搜索,有没有什么好方法处理一下,谢谢 😂

在网站上搜索直接报错,后台 Exception 如下

Method:      GET
URL:         /search?q=a
Controller:  search#index
RequestId:   8fcba3f8-9bee-4f9c-9d98-83558936d663
User-Agent:  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36
Remote IP:   172.19.0.8
Language:    en,zh-CN;q=0.9,zh;q=0.8
Server:      83a0e57b3091
Process:     11

--------------------------------------------------

#<ActionView::Template::Error: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"pages","index_uuid":"_na_","index":"pages"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"pages","index_uuid":"_na_","index":"pages"},"status":404}>


/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:202:in `__raise_transport_error'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:319:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/search.rb:183:in `search'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/searching.rb:51:in `execute!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/response.rb:31:in `response'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/response/base.rb:33:in `total'
/home/app/homeland/app/views/search/index.html.erb:5:in `_app_views_search_index_html_erb__2909668803154264808_70059658455800'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/template.rb:159:in `block in render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:170:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/template.rb:354:in `instrument_render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/template.rb:157:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:168:in `block in instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:168:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/template_renderer.rb:16:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/renderer.rb:44:in `render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/renderer/renderer.rb:25:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/rendering.rb:103:in `_render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/streaming.rb:219:in `_render_template'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/rendering.rb:84:in `render_to_body'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/rendering.rb:52:in `render_to_body'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/renderers.rb:142:in `render_to_body'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/abstract_controller/rendering.rb:25:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/rendering.rb:36:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/usr/local/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/core_ext/benchmark.rb:14:in `ms'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:46:in `block in render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:45:in `render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/implicit_render.rb:35:in `default_render'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/abstract_controller/base.rb:194:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/callbacks.rb:132:in `run_callbacks'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:168:in `block in instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:168:in `instrument'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/abstract_controller/base.rb:134:in `process'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.2.1/lib/action_view/rendering.rb:32:in `process'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal.rb:191:in `dispatch'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_controller/metal.rb:252:in `dispatch'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/routing/route_set.rb:34:in `serve'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/journey/router.rb:52:in `block in serve'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/journey/router.rb:35:in `each'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/journey/router.rb:35:in `serve'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/routing/route_set.rb:840:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/omniauth-1.8.1/lib/omniauth/strategy.rb:190:in `call!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/omniauth-1.8.1/lib/omniauth/strategy.rb:168:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/http_accept_language-2.1.1/lib/http_accept_language/middleware.rb:14:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-attack-5.4.2/lib/rack/attack.rb:182:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/exception_notification-4.3.0/lib/exception_notification/rack.rb:41:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb:36:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb:34:in `catch'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb:34:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/etag.rb:25:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/conditional_get.rb:25:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in `context'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb:38:in `call_app'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb:26:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb:26:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/ssl.rb:74:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rack-utf8_sanitizer-1.6.0/lib/rack/utf8_sanitizer.rb:22:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:524:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'

去机器上执行sudo make reindex,报错如下

$ sudo make reindex
Reindex ElasticSearch...
Starting homeland_redis ...
Starting homeland_redis ... done
Starting homeland_elasticsearch ... done
rake aborted!
NoMethodError: undefined method `bytesize' for nil:NilClass
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:87:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:43:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:38:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:262:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/bulk.rb:95:in `bulk'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/importing.rb:123:in `block in import'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/adapters/active_record.rb:106:in `block in __find_in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/relation/batches.rb:222:in `loop'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/relation/batches.rb:222:in `in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2.1/lib/active_record/querying.rb:11:in `find_in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/proxy.rb:96:in `method_missing'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/adapters/active_record.rb:105:in `__find_in_batches'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/importing.rb:122:in `import'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'
Tasks: TOP => elasticsearch:import:model
(See full trace by running task with --trace)
make: *** [reindex] Error 1

你试试:

$ docker-compose run app bundle exec rake elasticsearch:import:model CLASS=Topic FORCE=y
$ docker-compose run app bundle exec rake elasticsearch:import:model CLASS=Page FORCE=y
$ docker-compose run app bundle exec rake elasticsearch:import:model CLASS=User FORCE=y
huacnlee 回复

谢谢回复

三条均报类似下面的错误

$ docker-compose run app bundle exec rake elasticsearch:import:model CLASS=User FORCE=y
Starting homeland_postgresql ... done
Starting homeland_redis ...
Starting homeland_elasticsearch ... done
rake aborted!
NameError: uninitialized constant User
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `block in load_missing_constant'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `rescue in load_missing_constant'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:56:in `load_missing_constant'
(eval):1:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:49:in `eval'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:49:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'

Caused by:
NameError: uninitialized constant User
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
(eval):1:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:49:in `eval'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:49:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'
Tasks: TOP => elasticsearch:import:model
(See full trace by running task with --trace)
huacnlee 回复

另外,我加了 --trace 发现个挺神奇的地方

rake aborted!
Faraday::ConnectionFailed: Failed to open TCP connection to localhost:9200 (Network unreachable - connect(2) for "localhost" port 9200)
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:87:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:43:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:38:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:262:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/indices/delete.rb:44:in `delete'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:269:in `delete_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:229:in `create_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/importing.rb:116:in `import'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'

Caused by:
Errno::ENETUNREACH: Failed to open TCP connection to localhost:9200 (Network unreachable - connect(2) for "localhost" port 9200)
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:87:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:43:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:38:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:262:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/indices/delete.rb:44:in `delete'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:269:in `delete_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:229:in `create_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/importing.rb:116:in `import'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'

Caused by:
Errno::ENETUNREACH: Network unreachable - connect(2) for "localhost" port 9200
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:87:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:43:in `block in call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:38:in `call'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:143:in `build_response'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.4/lib/faraday/connection.rb:387:in `run_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/base.rb:262:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-api-5.0.5/lib/elasticsearch/api/actions/indices/delete.rb:44:in `delete'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:269:in `delete_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/indexing.rb:229:in `create_index!'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-model-5.0.2/lib/elasticsearch/model/importing.rb:116:in `import'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/elasticsearch-rails-5.0.2/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <main>'
/home/app/homeland/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `<main>'
Tasks: TOP => elasticsearch:import:model

说连不上本地 9200 端口…

我看了下 compose file,对 elasticsearch 端口的写法是

ports:
  - '9200'
  - '9300'

并没有显示指定,我以为是这里的问题… 调整成了

ports:
  - '9200:9200'
  - '9300:9300'

但依旧报同样的错误,调整后的 container

f34d63688977        elasticsearch:5-alpine     "/docker-entrypoint.…"   12 minutes ago       Up 12 minutes                    0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   homeland_elasticsearch

app.local.env配置文件的内容

#
# Global settings
#

RAILS_ENV=production --trace
SECRET_KEY_BASE=production

DATABASE_URL=postgres://postgres@postgresql:5432/homeland

REDIS_URL=redis://redis:6379/1
ELASTICSEARCH_HOST=elasticsearch:9200

那个你别调整,之前你能搜索不?如果能,那配置是对的

目前 make reindex 命令是有问题,我在 Ruby China 服务器看也是这样的。等我修复。

huacnlee 回复

是的 我觉得不是 compose 端口的问题 原来搜索是可用的

huacnlee 回复

好的 十分感谢

你用 docker-compose run app rails c 进入 Rails 控制台,然后执行:

Topic.__elasticsearch__.create_index!
Topic.import
User.__elasticsearch__.create_index!
User.import
Page.__elasticsearch__.create_index!
Page.import

先解决没索引的问题,确保服务可用

huacnlee 回复

执行

$ sudo make console
[sudo] password for aaron67:
Starting homeland_redis ... done
Starting homeland_postgresql ...
Starting homeland_elasticsearch ... done
Loading production environment (Rails 5.2.2.1)
irb(main):001:0> Topic.__elasticsearch__.create_index!
=> nil
irb(main):002:0> Topic.import
Traceback (most recent call last):
        1: from (irb):2
NoMethodError (undefined method `bytesize' for nil:NilClass)
irb(main):003:0> User.__elasticsearch__.create_index!
=> {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"users"}
irb(main):004:0> User.import
=> 0
irb(main):005:0> Page.__elasticsearch__.create_index!
=> {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"pages"}
irb(main):006:0> Page.import
=> 0
irb(main):007:0>

搜索功能已经 OK 了,感谢感谢

等您有空的时候 Fix 了 我再更新一哈 😀

遇到了新问题…SSL 证书不能刷新了…开了新帖,大佬啥时候有空的话看看吧。。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号