npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elasticsearch-sender

v1.1.1

Published

Make it easier to send bulk data Elasticsearch

Downloads

7

Readme

Elasticsearch Sender

Why?

Sending bulk data to Elasticsearch is common, but is not easy to do with the official ES client. In particular, creating new indexes for time-based data is not trivial. In ES, it is very inefficient to delete records by a query, and it is recommended in the official docs that you delete by index instead. This of course requires you to keep creating and writing data to the correct index. This library will handle that for you.

Usage

const esSend = require('elasticsearch-sender').buildSender({
    host: 'myElasticsearchHost.com',
    indexName: 'my-index',
    indexType: 'monthly',
    indexShape: {
        name: { type: 'keyword', index: true },
        numProcessed: { type: 'integer' },
        created: { type: 'date', index: true}
    },
    recordType: 'myRecordType'
});

...

esSend([{
    name: 'foo service',
    numProcessed: 42,
    created: new Date().toISOString()
}, {
    name: 'bar service',
    numProcessed: 2,
    created: new Date().toISOString() 
}])
.then(() => console.log('Items sent to Elasticsearch'));

buildSender(opts)

Builds a sender function that will automatically handle bulk processing and indexing

Opts
  • host Required. The Elasticsearch hostname
  • indexName Required. Will be used when creating an index. Must be all lowercase.
  • indexShape Required. An object describing indexes for the records being sent to ES. This is used for the properties field when creating the index in ES.
  • indexType Required. Must be one of 'monthly', 'daily', or 'single'. Controls the granularity of indexes. For instance, if 'daily', then a record created on Jan 25 2018 will be sent to the index named '${indexPrefix}-2018-01-25'. (This index will be automatically created as needed.) 'monthly' will only have the year and month in the index name. 'single' means only a single index called ${indexPrefix} will be ever be created and used.
  • recordType Required. The _type value for each record in Elasticsearch.
  • esLogLevel Optional. The log level for the Elasticsearch client. Defaults to 'info'

This returns a function that takes in an array of items and sends them all to Elasticsearch.

Disclaimer

This library is designed for my personal common use cases, namely, sending medium amounts of small pieces of data to a hosted ES server, allowing for me to run metrics queries easily. It does not try to get into more advanced use cases.