Code Monkey home page Code Monkey logo

elasticsearch-writable-stream's Introduction

elasticsearch-writable-stream

A writable stream for doing operations in Elasticsearch with support for bulk actions. Supports virtually all indexing operations including index, update, update_by_query, and delete.

This module used to be known as elasticsearch-bulk-index-stream, but was renamed because the package has added support for non-bulk actions.

build status modules status

npm badge

Usage

Format

The records written to the stream has to have the following format:

{
  index: 'name-of-index',
  type: 'recordType',
  id: 'recordId',
  parent: 'parentRecordType', // optional
  action: 'update', // optional (default: 'index')
  body: {
    name: 'Foo Bar'
  }
}

Buffering

The highWaterMark option set on the stream defines how many items will be buffered before doing a bulk operation. The stream will also write all buffered items if its is closed, before emitting the finish event.

The update_by_query action bypasses the buffer and gets executed at once since its not supported by the bulk API.

Flushing

Its also possible to send in the option flushTimeout to indicate that the items currently in the buffer should be flushed after the given amount of milliseconds if the highWaterMark haven't been reached.

Logging

A bunyan, winston or similar logger instance that have methods like debug, error and info may be sent in as options.logger to the constructor.

Example

var ElasticsearchWritableStream = require('elasticsearch-writable-stream');

var stream = new ElasticsearchWritableStream(elasticsearchClient, {
  highWaterMark: 256,
  flushTimeout: 500
});

someInputStream
  .pipe(stream)
  .on('error', function(error) {
    // Handle error
  })
  .on('finish', function() {
    // Clean up Elasticsearch client?
  })

API

See api.md.

See

Elasticsearch readable and writable streams. The main difference between the bulk writer in elasticsearch-streams and this library is that this library requires the index and type of the data being written to exist in the record instead of being set in a callback when the records written.

elasticsearch-streams also implements its own event named close to indicate that all the data has been written to Elasticsearch. This will break modules like pump that depend on the finish event.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.