diff --git a/README.md b/README.md index 9d13201..6ef3fae 100644 --- a/README.md +++ b/README.md @@ -5,25 +5,65 @@ is a simple node process that will follow a couchdb changes feed and updates ela You can also include an optional mapper. -``` +```sh npm install couch2elastic4sync -g ``` ## Usage +### Configuration file + [rc](http://npm.im/rc) is used to set to variables. For example, create a .couch2elastic4sync file with the following +```ini +database=http://localhost:5984/idx-edm-v5 +elasticsearch=http://elastic-1.com:9200/idx-edm-v5/listing +``` + +or pass the config file path explicity +```ini +couch2elastic4sync --config=path/to/configfile +``` + +Alternatively, the config file can be in JSON +```json +{ + "database": "http://localhost:5984/idx-edm-v5", + "elasticsearch": "http://elastic-1.com:9200/idx-edm-v5/listing" +} +``` - database=http://localhost:5984/idx-edm-v5 - elasticsearch=http://elastic-1.com:9200/idx-edm-v5/listing +### Load documents To load all the documents into elasticsearch, run +```sh +couch2elastic4sync load +``` - couch2elastic4sync load +### Keep documents in sync To keep a sync process going, run +```sh +couch2elastic4sync +``` - couch2elastic4sync +### Format and filter documents + +A `mapper` function can be passed from the config to format documents before being put to ElasticSearch: +```ini +database=http://localhost:5984/idx-edm-v5 +elasticsearch=http://elastic-1.com:9200/idx-edm-v5/listing +mapper=path/to/my-mapper.js +``` + +Where my-mapper.js could be something like +``` +module.exports = function (doc) { + // apply formatting here + return doc +} +``` +If the function returns empty, the document is filtered-out ## License diff --git a/lib/load.js b/lib/load.js index 12e3b11..cd477d7 100644 --- a/lib/load.js +++ b/lib/load.js @@ -22,7 +22,9 @@ module.exports = function (config, log, done) { var result = row.doc if (config.mapper) { result = config.mapper(row.doc) - if (result && config.addRaw) result[config.rawField] = row.doc + // return if the document was filtered-out + if (!result) return cb() + if (config.addRaw) result[config.rawField] = row.doc result._id = row.id // we need this to work correct } cb(null, result)