Firebase Search: A Bigger Boat

Chris Esplin
Google Cloud - Community
2 min readAug 13, 2016

Firebase provides query functionality meant for managing streams of data, not for faceted search. But you need to search your users, posts, subscriptions, etc. across multiple attributes.

Question: How on earth am I going to search this data???

Answer: You’re going to need a bigger boat.

Elasticsearch and Algolia FTW

Firebase doesn’t provide search functionality, because other services already have search all sewn up.

Meet Elasticsearch and Algolia.

These two services are much, much bigger boats.

Elasticsearch is open-source and specializes in warehousing enormous volumes of data and making it instantly searchable with Apache Lucene. Elasticsearch is so powerful that you can actually use it as it’s own NoSQL storage solution. Lots of companies feed all of their server logs directly to Elasticsearch for searchable storage. But most of us use it to power our apps’ most exotic search needs.

Algolia is a paid service for web and native search with an emphasis on ease of use and 1ms search results. You know those web forms where you see a list of suggestions as you type? That’s Algolia. It’s one of the cleanest dev services I’ve ever witnessed. The Algolia team deserves all of the props.

FirebaseSearch: Data Synchronization

I’ve written a small Node.js package and published in on NPM as quiver-firebase-search. FirebaseSearch takes a Firebase ref and config for Elasticsearch and/or Algolia and manages all of your data synchronization.

I just spent two hours writing a mean README. At least scan it before starting your implementation.

Here’s a barebones code sample. Note that I have a local ssh tunnel to port 9200 running to my Elasticsearch cluster. I’ve also hidden my Algolia config. I’m not giving you my api keys.

If you want to see the whole thing in action, I have a YouTube video for that too:

Search Your Indexes

Searching your index is best left to individual implementation, so FirebaseSearch does not provide any sort of search functionality.

Algolia has some great drop-in search bars. Or you can design your own and connect directly to Algolia from your client browser/app/whatever.

A bunch of turnkey services exist for Elasticsearch. Those should be simple to launch and configure, but I haven’t used them. I prefer to use Google Cloud Launcher and run my own server to proxy requests through a secure tunnel. I prefer it because it’s cheap. But it is extra work.

If you’re running your own Elasticsearch cluster, I recommend not messing with your cluster’s compute instances or config. Just launch it with Google’s Cloud Launcher and then front it with a server to provide access. You’ll probably have to fuss with your firewall rules a bit and maybe write some fancy Nginx directives or an ssh proxy command. It’s not brutal to implement. Just annoying. I have an example of a ridiculously complicated Nginx config that I came up with to proxy only search requests through to my cluster. I should have used an ssh tunnel. It would have been easier.

Questions?

Hit me up on Twitter at Chris Esplin or YouTube. I’m happy to answer questions and help as much as I can.

--

--