Installation
$ npm install geopipes-elasticsearch-backend
Note: you will need node
and npm
installed first.
The easiest way to install node.js
is with nave.sh by executing [sudo] ./nave.sh usemain stable
Interface
// Get a single record from elasticsearchBackendprototype // Get a multiple records from elasticsearchBackend.prototype.mget = function( Array ids, Object opts, Function cb ) // Index a new document in elasticsearchBackend.prototype.put = function( String key, Object val, Object opts, Function cb ) // Perform an arbitrary search against elasticsearchBackend.prototype.search = function( Object query, Object opts, Function cb ) // Create a bulk indexing stream which you can pipe index operations toBackend.prototype.createPullStream = function() // Find the nearest document to the supplied centroidBackend.prototype.reverseGeo = function( Object centroid, Object opts, Function cb ) // Perform a fields only reverse geocode to retrieve the admin heirachyBackend.prototype.findAdminHeirachy = function( Object centroid, Object opts, Function cb )
Basic Usage
You will need a little knowledge of elasticsearch schemas to build more advanced indexers; however this example should be enough to get you started.
var esclient = ;var Backend = ; var elasticsearch = esclient 'example1' 'type1' ; // Create a basic geo schemavar schema = mappings: type1: properties: name: type : 'string' center_point: type: 'geo_point' lat_lon: true // Create the schemaesclientindices;
You can view the indexed document here: http://localhost:9200/example1/type1/myid
Streaming Indexing
Note: the streaming library flushes in batches so you may need to wait a few seconds for the batch to be flushed.
var esclient = ;var Backend = ; var elasticsearch = esclient 'example2' 'type1' ;var stream = elasticsearch; stream;
You can view the indexed document here: http://localhost:9200/example2/type1/myid
NPM Module
The geopipes-elasticsearch-backend
npm module can be found here:
https://npmjs.org/package/geopipes-elasticsearch-backend
Contributing
Please fork and pull request against upstream master on a feature branch.
Pretty please; provide unit tests and script fixtures in the test
and test/fixtures
directories.
Running Unit Tests
$ npm test
Continuous Integration
Travis tests every release against node version 0.10