This guide assumes that you're using Rails 5.1 and have deployed to Heroku with the Searchbox Elastic Search add on.
Install the gems and run bundle install:
Add this code to the models that you want to add the search feature to:
Update the config/application.rb file and include this line inside of the application class definition:
Now you need to create an index for the model(s) that you want to be searchable, you can do this from the Rails console:
After you have created the index, this only creates it from this point on. It does not retroactively add historical records to the index. (See step 6 if you have historical records that you need to index)
Now you can run queries like this:
And it will return the records that match that query. This code can be placed in your controller and be taken from traditional text boxes.
Optional Step 6
If you are adding Elastic Search to an application with historical records, you will need to add each record to the index, you can do it with a script like this: