Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geopipes-elasticsearch-backend

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geopipes-elasticsearch-backend

Elasticsearch backend with support for streaming bulk indexing

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40
increased by1233.33%
Maintainers
4
Weekly downloads
 
Created
Source

Installation

$ npm install geopipes-elasticsearch-backend

NPM

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 elasticsearch
Backend.prototype.get = function( String key, Object opts, Function cb )

// Get a multiple records from elasticsearch
Backend.prototype.mget = function( Array ids, Object opts, Function cb )

// Index a new document in elasticsearch
Backend.prototype.put = function( String key, Object val, Object opts, Function cb )

// Perform an arbitrary search against elasticsearch
Backend.prototype.search = function( Object query, Object opts, Function cb )

// Create a bulk indexing stream which you can pipe index operations to
Backend.prototype.createPullStream = function()

// Find the nearest document to the supplied centroid
Backend.prototype.reverseGeo = function( Object centroid, Object opts, Function cb )

// Perform a fields only reverse geocode to retrieve the admin heirachy
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' );

// Create a basic geo schema
var schema = {
  mappings: {
    type1: {
      properties: {
        name: { type : 'string' },
        center_point: { type: 'geo_point', lat_lon: true }
      }
    }
  }
}

// Create the schema
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

Build Status

Keywords

FAQs

Package last updated on 13 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc