I am using:
elasticsearch: 6.1.0
searchkick : 3.1.0
I have a model Item that has_many Tags through:... In the Tag's after_commit callback I am doing something like self.items.each(&:reindex) and randomly get this stack trace below:
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Cannot delete indices that are being snapshotted: [[items_production_20180820164224593/Puk5nXOQQh-JB4tGzGwGnA]]. Try again after snapshot finishes or cancel the currently running snapshot."}],"type":"illegal_argument_exception","reason":"Cannot delete indices that are being snapshotted: [[items_production_20180820164224593/Puk5nXOQQh-JB4tGzGwGnA]]. Try again after snapshot finishes or cancel the currently running snapshot."},"status":400}
from elasticsearch/transport/transport/base.rb:205:in `__raise_transport_error'
from elasticsearch/transport/transport/base.rb:323:in `perform_request'
from elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from elasticsearch/transport/client.rb:131:in `perform_request'
from elasticsearch/api/namespace/common.rb:21:in `perform_request'
from elasticsearch/api/actions/indices/delete.rb:54:in `delete'
from searchkick/index.rb:25:in `delete'
from searchkick/index.rb:116:in `block in clean_indices'
from searchkick/index.rb:115:in `each'
from searchkick/index.rb:115:in `clean_indices'
from searchkick/index.rb:265:in `reindex_scope'
from searchkick/index.rb:195:in `reindex'
from searchkick/model.rb:59:in `searchkick_reindex'
from app/models/tag.rb:17:in `reindex_item'
from active_support/callbacks.rb:426:in `block in make_lambda'
from active_support/callbacks.rb:271:in `block in simple'
from active_support/callbacks.rb:517:in `block in invoke_after'
from active_support/callbacks.rb:517:in `each'
from active_support/callbacks.rb:517:in `invoke_after'
from active_support/callbacks.rb:133:in `run_callbacks'
from active_support/callbacks.rb:816:in `_run_commit_callbacks'
from active_record/transactions.rb:345:in `committed!'
from active_record/connection_adapters/abstract/transaction.rb:119:in `commit_records'
from active_record/connection_adapters/abstract/transaction.rb:214:in `block in commit_transaction'
from monitor.rb:214:in `mon_synchronize'
from active_record/connection_adapters/abstract/transaction.rb:204:in `commit_transaction'
from active_record/connection_adapters/abstract/transaction.rb:243:in `block in within_new_transaction'
from monitor.rb:214:in `mon_synchronize'
from active_record/connection_adapters/abstract/transaction.rb:227:in `within_new_transaction'
from active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
from active_record/transactions.rb:212:in `transaction'
from active_record/transactions.rb:383:in `with_transaction_returning_status'
from active_record/transactions.rb:310:in `block in save'
from active_record/transactions.rb:325:in `rollback_active_record_state!'
from active_record/transactions.rb:309:in `save'
from active_record/suppressor.rb:44:in `save'
from active_admin/resource_controller/data_access.rb:155:in `block in save_resource'
from active_support/core_ext/object/try.rb:19:in `public_send'
from active_support/core_ext/object/try.rb:19:in `try!'
from active_support/core_ext/object/try.rb:8:in `try'
from active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
from active_admin/resource_controller/data_access.rb:154:in `save_resource'
from active_admin/resource_controller/data_access.rb:144:in `block in create_resource'
from active_support/core_ext/object/try.rb:19:in `public_send'
from active_support/core_ext/object/try.rb:19:in `try!'
from active_support/core_ext/object/try.rb:8:in `try'
from active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
from active_admin/resource_controller/data_access.rb:143:in `create_resource'
from inherited_resources/actions.rb:33:in `create'
from action_controller/metal/basic_implicit_render.rb:6:in `send_action'
from abstract_controller/base.rb:194:in `process_action'
from action_controller/metal/rendering.rb:30:in `process_action'
from abstract_controller/callbacks.rb:42:in `block in process_action'
from active_support/callbacks.rb:109:in `block in run_callbacks'
from raven/integrations/rails/controller_transaction.rb:7:in `block in included'
from active_support/callbacks.rb:118:in `instance_exec'
from active_support/callbacks.rb:118:in `block in run_callbacks'
from react/rails/controller_lifecycle.rb:31:in `use_react_component_helper'
from active_support/callbacks.rb:118:in `block in run_callbacks'
from active_support/callbacks.rb:136:in `run_callbacks'
from abstract_controller/callbacks.rb:41:in `process_action'
from action_controller/metal/rescue.rb:22:in `process_action'
from action_controller/metal/instrumentation.rb:34:in `block in process_action'
from active_support/notifications.rb:168:in `block in instrument'
from active_support/notifications/instrumenter.rb:23:in `instrument'
from active_support/notifications.rb:168:in `instrument'
from action_controller/metal/instrumentation.rb:32:in `process_action'
from action_controller/metal/params_wrapper.rb:256:in `process_action'
from searchkick/logging.rb:209:in `process_action'
from active_record/railties/controller_runtime.rb:24:in `process_action'
from abstract_controller/base.rb:134:in `process'
from action_view/rendering.rb:32:in `process'
from action_controller/metal.rb:191:in `dispatch'
from action_controller/metal.rb:252:in `dispatch'
from action_dispatch/routing/route_set.rb:52:in `dispatch'
from action_dispatch/routing/route_set.rb:34:in `serve'
from action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
from action_dispatch/routing/mapper.rb:48:in `serve'
from action_dispatch/journey/router.rb:52:in `block in serve'
from action_dispatch/journey/router.rb:35:in `each'
from action_dispatch/journey/router.rb:35:in `serve'
from action_dispatch/routing/route_set.rb:840:in `call'
from clearance/rack_session.rb:23:in `call'
from rack/tempfile_reaper.rb:15:in `call'
from rack/etag.rb:25:in `call'
from rack/conditional_get.rb:38:in `call'
from rack/head.rb:12:in `call'
from action_dispatch/http/content_security_policy.rb:18:in `call'
from rack/session/abstract/id.rb:232:in `context'
from rack/session/abstract/id.rb:226:in `call'
from action_dispatch/middleware/cookies.rb:670:in `call'
from action_dispatch/middleware/callbacks.rb:28:in `block in call'
from active_support/callbacks.rb:98:in `run_callbacks'
from action_dispatch/middleware/callbacks.rb:26:in `call'
from action_dispatch/middleware/debug_exceptions.rb:61:in `call'
from action_dispatch/middleware/show_exceptions.rb:33:in `call'
from rails/rack/logger.rb:38:in `call_app'
from rails/rack/logger.rb:26:in `block in call'
from active_support/tagged_logging.rb:71:in `block in tagged'
from active_support/tagged_logging.rb:28:in `tagged'
from active_support/tagged_logging.rb:71:in `tagged'
from rails/rack/logger.rb:26:in `call'
from action_dispatch/middleware/remote_ip.rb:81:in `call'
from action_dispatch/middleware/request_id.rb:27:in `call'
from rack/method_override.rb:22:in `call'
from rack/runtime.rb:22:in `call'
from active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
from action_dispatch/middleware/executor.rb:14:in `call'
from action_dispatch/middleware/static.rb:127:in `call'
from heroku-deflater/skip_binary.rb:19:in `call'
from rack/deflater.rb:34:in `call'
from heroku-deflater/serve_zipped_assets.rb:54:in `call'
from rack/sendfile.rb:111:in `call'
from action_dispatch/middleware/ssl.rb:74:in `call'
from raven/integrations/rack.rb:51:in `call'
from rails/engine.rb:524:in `call'
from puma/configuration.rb:225:in `call'
from puma/server.rb:632:in `handle_request'
from puma/server.rb:446:in `process_client'
from puma/server.rb:306:in `block in run'
from puma/thread_pool.rb:120:in `block in spawn_thread'
This happens pretty often, but I haven't been able to establish a pattern yet.
It looks like the code is recreating the index (doing a full reindex) instead of indexing individual items. You likely don't want to do this in callbacks.
Closing due to no response
Sorry for the lack of response. The solution was to just index the individual item as you suggested.
Thank you for your help!
Most helpful comment
It looks like the code is recreating the index (doing a full reindex) instead of indexing individual items. You likely don't want to do this in callbacks.