el-client v1.0.6
El-client
An evolving stripped down, simplified & easy-to-use Javascript client for ElasticSearch. This library is exported as a UMD module.
Quick Setup and Usage
npm i --save el-client (local project)
const elc = require('el-client');
let options = {
protocol: 'http', //or https (important)
host: 'localhost',
port: 9200,
auth: 'username:password',
headers: {
accept: 'application/json',
authorization: '<type> <credentials>',//`Basic ${ new Buffer(username:password).toString('base64') }`
/** and/or any default header properties **/
}
};
let client = new elc.Client( options );
let existsOptions = { index: 'test_index' };
//checking if the index exists
client
.exists(
existsOptions,
(err, exists) => {
if(err) console.log('err: ', err);
else console.log('exists?: ', exists);
}
)
.run();
Authorization
Currently, authorization into an elasticsearch instance can be done in two ways:
- Via Auth Property:
set `auth` property in the form `username:password` in the options for the client instantiation.
there is an example above for you to reference.
- Via HTTP/HTTPS Headers:
along with any other default headers properties, you can add your Basic Base64 Encoded token as an authorization property:
`Basic ${ new Buffer(username:password).toString('base64') }`
there is an example reference with this approach as well.
this approach not withstanding, you may use another approach via http/https headers that works for you.
Timeout
All requests by default times out in 15 seconds. This might seem extreme but I believe handling long running requests asynchronously. However, you can overwrite this in the client options by setting the time to whatever you like. It takes seconds like:
let options = {
//other options
timeout: 30
};
Version
1.0.6
Elasticsearch version compatibility
6.x ~ 6.2
New in Version 1.0.6
Cluster
- basicStats( callback ): void. ( formerly stats( .. ) )
- createMapping( options, callback ): void.
Reads
- count( options, callback ): void.
- explain( options, callback ): void.
Breaking Changes
Fixed breaking changes with 6.2.2. All functions currently work on 6.x. I cannot guarantee backward compatibility; for that use an older version of this library; 1.0.2 or less
API
- CLUSTER FUNCTIONS DOC.
- CREATE FUNCTIONS DOC.
- READ FUNCTIONS DOC.
- UPDATE FUNCTIONS DOC.
- DELETE FUNCTIONS DOC.
- HELPER METHODS DOC.
Contribution
Any one that wants to help with anything from testing, expanding the scope of features to documentation should seek a request via the issue feature on GitLab.
Issues
Please report issues as you see them during usage. It will help improve this library as a whole. Thank you.
Credits
- Libraries / Modules
- curlrequest by @chriso.
- is-valid-json by @shubhamoli.
- lodash.
- rxjs.
For Testing Only: