elastic-client-advanced
v1.1.5
Published
Elastic client that works on some protocol(count,default) and strategies
Downloads
9
Maintainers
Readme
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
- COUNT: Want to limit enteries in ES on basis of some key count
- DEFAULT: Behaves same as normal ES Client
Have a problem? Come chat with us!
Maintained by
Getting started.
Elastic Client Advanced will work on all systems.
npm install --save elastic-client-advanced
Usage
- 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'
});
- 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
});
- 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);
});