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
Backend.prototype.get = function( String key, Object opts, Function cb )
Backend.prototype.mget = function( Array ids, Object opts, Function cb )
Backend.prototype.put = function( String key, Object val, Object opts, Function cb )
Backend.prototype.search = function( Object query, Object opts, Function cb )
Backend.prototype.createPullStream = function()
Backend.prototype.reverseGeo = function( Object centroid, Object opts, Function cb )
Backend.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 = require('pelias-esclient')();
var Backend = require('geopipes-elasticsearch-backend');
var elasticsearch = new Backend( esclient, 'example1', 'type1' );
var schema = {
mappings: {
type1: {
properties: {
name: { type : 'string' },
center_point: { type: 'geo_point', lat_lon: true }
}
}
}
}
esclient.indices.create( { index: 'example1', body: schema }, function( err, res ){
var opts = null;
var centroid = {
'lat': 50.1,
'lon': 100.45
};
var doc = {
'name': 'My POI',
'center_point': centroid
};
elasticsearch.put( 'myid', doc, opts, function( err, res ){
console.log( 'put', err, res );
elasticsearch.reverseGeo( centroid, opts, function( err, res ){
console.log( 'reverse geosearch', err, res );
});
});
});
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 = require('pelias-esclient')();
var Backend = require('geopipes-elasticsearch-backend');
var elasticsearch = new Backend( esclient, 'example2', 'type1' );
var stream = elasticsearch.createPullStream();
stream.write({
'id': 'myid',
'name': 'My POI',
'center_point': {
'lat': 50.1,
'lon': 100.45
}
});
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