1.1.5 • Published 6 years ago

elastic-client-advanced v1.1.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Elastic Client Advanced

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

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

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);
    });
1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago