resourceful-couchelastic
The goal of CouchElastic is to provide seamless full-text and parametric search to Node.js apps, accomplished via Flatiron's Resourceful ODM layer and the awesome power of CouchDB and Elasticsearch.
Configuration
Start up an empty instance of CouchDB and an empty instance of Elasticsearch, then do this:
var resourceful =Couchelastic = Couchelastic;resourcefulenginesCouchelastic = Couchelastic; // patch in the engineresourceful;
From this point onwards each Resource
that you define will have its data stored in your specified
CouchDB cluster and have an Elasticsearch indexing river configured to index the data for searching.
Define a resource
Assuming you're already defining resources with Resourceful nothing more is required, but there are some additional options you might want to use. Everything specified within the options.search is passed straight into ES's Mapping API, allowing you fine-grained control over how that individual field is treated in the index.
var Creature = resourceful;
Synchronise your schema
The sync()
method sets up your data sources for you. Until you sync you can save()
and get()
but not much more.
For each Resource
type sync
does the following:
- Saves a CouchDB design document
- Saves an Elasticsearch Mapping document
- Creates a River on the Elasticsearch cluster that listens to CouchDB's replication stream
You'll need to sync
after you make any significant design changes so that they're carried through to the schemas of both servers. Be aware that changing the data type of a field after data has already been indexed can be problematic.
Searching
Assuming you've defined a Creature as per the Resourceful docs you should be able to search your database in free text like this.
Creature;
You can also search using the Elasticsearch query DSL, for example the following fuzzy
query would also match the word "oscar"
Actor;
Or using Resoureceful's parametric query method Resourece.find()
Creature;
Joining
If you have two data types related by a one-to-many foreign key you can do this (many-many not available yet):
Creature;
Security
If some of your Resource data is sensitive you might want to block it from being indexed
var Employee = resourceful;
TODO - clean up the object search API and allow faceting etc.
Installation
npm install resourceful-couchelastic`
Tests
All tests are written with vows and should be run with npm:
$ npm test