Skip to content

Commit

Permalink
Merge pull request ryanramage#13 from maxlath/fixMapper
Browse files Browse the repository at this point in the history
Fixing mapper to be used as a filter function and documenting
  • Loading branch information
ryanramage authored Aug 22, 2016
2 parents c072a75 + db88b28 commit 2396e01
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lib/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2396e01

Please sign in to comment.