I have a Rails application hosted in Heroku and it uses the searchkick
gem version 4.6.1
. I'm using Bonsai add-on.
I only have one model that uses searchkick:
class Program < ApplicationRecord
searchkick
# blah blah blah
scope :search_import, -> { includes(:provider, :categories, :address, :current_published_schedules) }
def search_data
{
name: name,
description: description,
provider_name: name,
categories: categories.pluck(:name),
start_dates: current_published_schedules.pluck(:start_date).sort,
registration_opens_at: current_published_schedules.pluck(:registration_opens_at),
registration_closes_at: current_published_schedules.pluck(:registration_closes_at),
city: address&.city,
state: address&.state,
zipcode: address&.zipcode,
program_type: program_type
}
end
def should_index?
published?
end
I have this rake task:
namespace :searchkick do
desc "Reindex models"
task reindex: :environment do
Searchkick::ReindexWorker.perform_async
end
end
and this worker:
module Searchkick
class ReindexWorker
include Sidekiq::Worker
sidekiq_options retry: 3
def perform
Program.reindex
end
end
end
My procfile is:
release: bash ./release-tasks.sh
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
worker: bundle exec sidekiq -q default -q low -c 2
clock: bundle exec clockwork config/clock.rb
and release-tasks.sh
looks like this:
echo "Running Release Tasks"
echo "Migrating:"
bundle exec rake db:migrate
echo "Indexing (searchkick):"
bundle exec rake searchkick:reindex
When I deploy, I occasionally see the following error in my error monitoring tool:
Searchkick::ImportErrorsearchkick:index
{"type"=>"index_not_found_exception", "reason"=>"no such index [programs_production_20230321124906238]", "index_uuid"=>"Yn2PekrDRvi6ZUI6H1cflg", "index"=>"programs_producti ...
When I run
heroku run bundle exec rake searchkick:reindex --app my-prod-app
it runs fine.
I don't understand how indexes work. I am overwhelmed by the amount of information so I don't even know where to start looking.
Questions:
- Is there anything wrong with my setup that would be causing this issue?
- Is
Program.reindex
what I should be running after deploy or should this be something else? - Why does the index have a timestamp? (noob elastic-search question, I come from postgres background where indexes just have a name). Why would it not find it?