Add Elasticsearch with elasticsearch-rails #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
The goal of the
rails-example
application is to serve as an example web application for learning how to deploy apps to the Reclaim the Stack platform. Currently it uses Postgres and Redis but since the platform also supports Elasticsearch we want the demo application to use this as well.What
Indexes the
Post
andLink
models in Elasticsearch to allow for doing full text search across both models. Each document in the index will use atitle
field with a high priority and acontent
field with lower priority (taken fromPost#body
andLink#description
respectively).Feel free to compare with the 0 dependency version at #1.
Lines of Code
Implementation: ~160 LOC
Dependencies: 16,698 LOC
Time spent
Didn't keep track but approximately 2 hours (would have been closer to 1 hour if it wasn't for the issues).
Issues
Had to monkey patch
Elasticsearch::Client#verify_with_version_or_header
because elastic/elasticsearch-ruby#1429 (comment) (to allow compatibility with the fully open source licensed OpenSearch fork of Elasticsearch)Also had to enable
eager_load
for all environments to accurately keep track of which models have included theSearchable
module. Fun fact: I tried using an explicit manually managedSearchable::MODELS
constant to work around this but this caused some terrible issue where theincluded do
block would only run for one of the searchable models 🤦Learnings
I copy pasted some things out of the elasticsearch-rails and elasticsearch-model README files to get started. I still know nothing of what is going on with Elasticsearch under the hood.
Dependencies
Explicit dependencies [3127 LOC]
elasticsearch-model-7.2.1
elasticsearch-rails-7.2.1
Secondary dependencies [83 LOC]
elasticsearch-7.17.7
Tertiary dependencies [10816 LOC]
elasticsearch-api-7.17.7
elasticsearch-transport-7.17.7
hashie-5.0.0
faraday-1.10.3
Quaternary dependencies [2432 LOC]
multi_json
faraday-em_http-1.0.0
faraday-em_synchrony-1.0.0
faraday-excon-1.1.0
faraday-httpclient-1.0.1
faraday-multipart-1.0.4
faraday-net_http-1.0.1
faraday-net_http_persistent-1.2.0
faraday-patron-1.0.0
faraday-rack-1.0.0
faraday-retry-1.0.3
Quinary dependencies [240 LOC]
multipart-post-2.3.0