So, we've probably mentioned that we're using ElasticSearch to power Gander. What we haven't talked about so much is why, and how we're using it under the hood. When we were building out the back end for Gander, the very first thing we wanted to know is what search platform would meet our needs best. It needed to be powerful and it needed to be fast. If it had a great API to work against and was easy to set up, well, that's just gravy on top. ElasticSearch had these qualities in spades. The other major platform we looked at was Solr, which, like ElasticSearch, is built on top of Lucene. The two are actually somewhat similiar, with Solr being older and designed more for standard search applications. ElasticSearch is newer, and its API, setup and underlying model reflect this. For the kind of application we're building, ElasticSearch is the better fit.
Elasticsearch works by creating indexes over whatever one is trying to search. These indexes track a subset of the data we want to search, and are organized in such a way so that these searches will be fast. To actually keep track of our data, we store it all in CouchDB. However, we still needed to get our data to Elasticsearch so that it could create indexes over that data. Luckily, there's a pretty smooth way to do it. CouchDb has a concept called rivers where any changes made to the underlying data show up as a change on the river. The changes go downstream along the river, one might say. Elasticsearch has a river plugin for reading these changes. With the right configuration, any changes to the data we want to search will automatically be propagated to Elasticsearch and reindexed, so our search results will always be up to date.
Gander is primarily Ruby on Rails, and it is there that we create new search requests and display our search results. It needs to be able to interact with Elasticsearch, too. Elasticsearch has a pretty great client-side API, but we didn't want to reinvent the wheel, or tire, so to speak. We're using the Tire gem instead. It lets us make requests and display their results with a minimum amount of fuss. Basically, when a user enters a new query that they want to search, we can parse that query and pass it to Tire. Tire will then use the Elasticsearch API to make the search request on our behalf. It then will return us the search results in a nice format, which we then display to the user on the page. Easy peasy, lemon squeezy.
And that's pretty much it. Elasticsearch is an easy search platform to work with - besides some distributable aspects, this is a basic overview of our entire search architecture. Questions? Comments? Want to know about some specifics? Contact us!
[Image via