elastic-client-advanced

1.1.5 • Public • Published

Elastic Client Advanced

Node library to save data on ES based on some protocols.

Elastic Client Advanced

This library works on some protocols to save data in ES. Currently supporting only 2 protocols. Will be adding many more in future

Protocols Supported

  1. COUNT: Want to limit enteries in ES on basis of some key count
  2. DEFAULT: Behaves same as normal ES Client
Linux OS X Windows
Passed

Have a problem? Come chat with us!

LinkedIn
Twitter
Github
Gmail

Maintained by

Yogesh Yadav

Getting started.

Elastic Client Advanced will work on all systems.

npm install --save elastic-client-advanced

Usage

  1. Create a ES client and provide to lib, intentionally not taking es config as its redundant to have more than one client
const Q = require('q');
const ElasticClient = require('elastic-client-advanced');
const Elasticsearch = require('elasticsearch');
let client = new Elasticsearch.Client({
    host: {
        host: '127.0.0.1',
        port: 9200
    }
    // log: 'trace'
});
  1. Create a object of advanced ES Client
// 2nd Param is optional but its better if you provide
let elasticClient = new ElasticClient(client, {
    logger: console.log
});
  1. Doing following steps
    a. Init the client
    b. Set protocol, here setting count protocol for column customerId
    c. Set Fields for given type, other fields will be ingored
    d. Insert in ES
let index = 'keyvalueindex';
let type = 'keyvaluetype';
let columns = ['a', 'b', 'c'];
const sleep = require('sleep');

new Q(undefined)
    .then(function(result) {
        return elasticClient.init();
    })
    .then(function() {
        return elasticClient.setProtocol({
            name: 'serviceName',
            protocol: 'COUNT',
            protocolField: 'customerId',
            protocolMax: 10
        });
    })
    .then(function() {
        return elasticClient.setFieldsForIndexNType(index, type, columns);
    })
    .then(function() {
        return elasticClient.insert({
            index: index,
            type: type,
            customerId: 1,
            body: {
                c: 1,
                b: 1
            }
        });
    })
    .then(function() {
        sleep.sleep(1);
        return Q.resolve();
    })
    .then(function() {
        return elasticClient.insert({
            index: index,
            type: type,
            customerId: 1,
            body: {
                c: 1,
                b: 2
            }
        });
    })
    .then(function() {
        return Q.resolve();
    })
    .fail(function(error) {
        logger.error(error);
    });

/elastic-client-advanced/

    Package Sidebar

    Install

    npm i elastic-client-advanced

    Weekly Downloads

    3

    Version

    1.1.5

    License

    MIT

    Unpacked Size

    102 kB

    Total Files

    12

    Last publish

    Collaborators

    • yogeshyadav108098